예제 #1
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();
     $categoryModel = new GalleryCategory();
     $treeParents = TreeHelper::build($categoryModel->find()->addOrderBy('tree')->addOrderBy('lft')->all());
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model, 'treeParents' => $treeParents]);
     }
 }
예제 #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()) {
         if (!empty($_FILES['UploadForm']['tmp_name']['file'])) {
             $model->attachImage($_FILES['UploadForm']['tmp_name']['file']);
             if ($model->errors) {
                 var_dump($model->errors);
                 die;
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #3
0
 /**
  * Save Gallery model
  * @param bool $insert
  */
 public function saveGallery($insert = true)
 {
     $gallery = new Gallery();
     if ($this->item_id) {
         $gallery->id = $this->item_id;
     }
     $gallery->isNewRecord = $insert;
     $gallery->attributes = $this->toArray();
     $gallery->public = is_array($this->boxes) && in_array(self::PROPERTY_PUBLIC, $this->boxes) ? 1 : 0;
     $gallery->active = is_array($this->boxes) && in_array(self::PROPERTY_ACTIVE, $this->boxes) ? 1 : 0;
     $gallery->save();
 }