Ejemplo n.º 1
0
 /**
  * Creates a new Projects model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Projects();
     $model->active = 1;
     if ($model->load(Yii::$app->request->post())) {
         $image = Upload::uploadImage($model);
         //var_dump($image); exit;
         $images = Upload::uploadImages($model);
         $attachments = Upload::uploadFiles($model);
         if ($model->save()) {
             // upload only if valid uploaded file instance found
             if ($image !== false) {
                 $path = Upload::getImageFile($image);
                 $image->saveAs($path);
             }
             if ($images !== false) {
                 foreach ($images as $img) {
                     $path = Upload::getImageFile($img);
                     //var_dump($path); exit;
                     $img->saveAs($path);
                 }
             }
             if ($attachments !== false) {
                 foreach ($attachments as $attachment) {
                     $path = Upload::getAttachmentFile($attachment);
                     $attachment->saveAs($path);
                 }
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }