Ejemplo n.º 1
0
 /**
  * Creates a new BlogCatalog model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     //if(!Yii::$app->user->can('createPost')) throw new HttpException(401, 'No Auth');
     $model = new BlogCatalog();
     $model->loadDefaultValues();
     if (isset($_GET['parent_id']) && $_GET['parent_id'] > 0) {
         $model->parent_id = $_GET['parent_id'];
     }
     if ($model->load(Yii::$app->request->post())) {
         $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]);
     }
 }