public function actionCreate()
 {
     $model = new NewsCategory();
     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 NewsCategory model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new NewsCategory();
     $postInfo = Yii::$app->request->post();
     if (!empty($postInfo)) {
         if ($model->load($postInfo) && $model->save()) {
             Yii::$app->getSession()->setFlash('success', '添加成功!');
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             throw new ServerErrorHttpException('添加分类失败,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE));
             return $this->redirect(['create']);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 3
0
 /**
  * @param $input
  * @return bool
  */
 public function createCategory($input)
 {
     $category = new NewsCategory();
     $category->name = $input['name'];
     $category->pid = $input['pid'];
     return $category->save();
 }