/**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new CategoryModel model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     $model->scenario = 'create';
     $model->created_at = time();
     $model->updated_at = time();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         $model->categoryArray = CategoryCommon::getCategoryList();
         return $this->render('create', ['model' => $model]);
     }
 }
Esempio n. 3
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('admin')) {
         $model = new Category();
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->category_id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return parent::actionLogin();
     }
 }
Esempio n. 4
0
 public function actionCreate()
 {
     $error = '';
     $model = new Category();
     $data['csrf'] = Yii::$app->request->post('_csrf');
     $data['Category'] = Yii::$app->request->post();
     if (isset($data['Category']['submit'])) {
         $data['Category']['create_date'] = time();
         $data['Category']['user_create'] = \Yii::$app->user->id;
         $data['Category']['intro'] = $data['Category']['editor1'];
         if ($model->load($data) && $model->save()) {
             return $this->redirect(['index']);
         } else {
             $error = $model->getErrors();
             return $this->render('create', ['error' => $error]);
         }
     }
     return $this->render('create', ['error' => $error]);
 }