コード例 #1
0
 public function actionCreate()
 {
     $gallery = new Gallery();
     if ($gallery->load($_POST) && $gallery->save()) {
         $gallery->uploadedImages = UploadedFile::getInstances($gallery, 'uploadedImages');
         $gallery->saveImagesOnDisk();
         Yii::$app->session->setFlash('success', Yii::t('app', "Gallery {$gallery->name} created successfully"));
         return $this->redirect(['index']);
     }
     return $this->render('create', compact('gallery'));
 }
コード例 #2
0
 /**
  * Creates a new Gallery model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Gallery();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $imageName = $model->id;
         $model->file = UploadedFile::getInstance($model, 'file');
         if ($model->file != null) {
             $model->file->saveAs('../../frontend/web/images/gallery_images/' . $imageName . '.' . $model->file->extension);
             $model->gallery_picture = 'images/gallery_images/' . $imageName . '.' . $model->file->extension;
         }
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }