Esempio n. 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new MCompany();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['MCompany'])) {
         $model->attributes = $_POST['MCompany'];
         $brandImage = CUploadedFile::getInstance($model, 'image_id');
         if ($brandImage instanceof CUploadedFile) {
             $image = new MImage();
             $path_parts = pathinfo($brandImage->getName());
             $file_name = time() . "." . $path_parts['extension'];
             $path = Yii::app()->storagePath . "brand" . DIRECTORY_SEPARATOR . $file_name;
             $brandImage->saveAs($path);
             $image->created = time();
             $image->path = "/storage/brand/" . $file_name;
             $image->created_by = Yii::app()->user->id;
             $image->save(false);
         }
         $model->image_id = $image->id;
         $model->created = time();
         $model->created_by = Yii::app()->user->id;
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }