Пример #1
0
 /**
  * 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]);
     }
 }
Пример #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();
     }
 }
 public function actionCreate()
 {
     $model = new Category();
     $roots = ArrayHelper::map(Category::find()->roots()->all(), 'name', 'name');
     if ($model->load(\Yii::$app->request->post())) {
         $post = \Yii::$app->request->post('Category');
         if ($post['parent'] == null) {
             $parent = new Category(['name' => $post['name']]);
             $parent->makeRoot();
         } else {
             $parent = Category::findOne(['name' => $post['parent']]);
             $child = new Category(['name' => $post['name']]);
             $child->appendTo($parent);
         }
     } else {
         return $this->render('create', ['model' => $model, 'roots' => $roots]);
     }
 }
Пример #5
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]);
 }