/** * Creates a new CmsCatalog model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { //if(!Yii::$app->user->can('createYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth')); $model = new CmsCatalog(); $model->loadDefaultValues(); if (Yii::$app->request->get('parent_id')) { $model->parent_id = Yii::$app->request->get('parent_id'); $parentCatalog = CmsCatalog::findOne(Yii::$app->request->get('parent_id')); $model->page_type = $parentCatalog->page_type; } if ($model->load(Yii::$app->request->post())) { if (isset($parentCatalog)) { $model->page_type = $parentCatalog->page_type; } $model->banner = UploadedFile::getInstance($model, 'banner'); if ($model->validate()) { if ($model->banner) { $bannerName = Yii::$app->params['blogUploadPath'] . date('Ymdhis') . rand(1000, 9999) . '.' . $model->banner->extension; $model->banner->saveAs(Yii::getAlias('@frontend/web') . DIRECTORY_SEPARATOR . $bannerName); $model->banner = $bannerName; } $model->save(false); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } }