/** * 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]); } }
/** * 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]); } }