/**
  * 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->category_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #2
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @param int $id id of the parent category
  * @return mixed
  */
 public function actionCreate($id = null)
 {
     $categories = Category::find()->all();
     $model = new Category();
     $model->parent_id = $id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'categories' => $categories]);
     }
 }
Пример #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('createYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
     $model = new Category();
     $model->loadDefaultValues();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #4
0
 /**
  * Creates a new Category model.
  * If creation is successful, the browser will be redirected to the main 'index' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Category();
     $model->scenario = 'create';
     $dataProvider = new ActiveDataProvider(['query' => Category::find()]);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('message', 'The category has been created successfully.');
         return $this->redirect('index', ['dataProvider' => $dataProvider]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #5
0
 public function actionCreatecategory()
 {
     $category = new Category();
     $data = \Yii::$app->request->post("Category");
     if (!empty($data)) {
         $category->load(\Yii::$app->request->post());
     }
     if (!empty($data) && $category->validate() && $category->save()) {
         return $this->render('success_create_category');
     }
     return $this->render('category_edit', ['category' => $category, 'parents' => Category::getList()]);
 }
Пример #6
0
 /**
  * Creates a new Meta model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($parent = 0)
 {
     $model = new Category();
     $model->parent = intval($parent);
     if (Yii::$app->request->isPost) {
         if ($model->load(Yii::$app->request->post())) {
             if ($model->save()) {
                 return $this->redirect(['index']);
             }
         }
     }
     return $this->render('create', ['model' => $model]);
 }
 public function actionAdd()
 {
     $model = new Category();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             Yii::$app->session->setFlash('success', '成功添加分类“' . $model->name . '”。');
             return $this->redirect(['index']);
         } else {
             Yii::$app->session->setFlash('danger', '分类添加失败。');
         }
     }
     return $this->render('form', ['model' => $model]);
 }
 /**
  * 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();
     try {
         if ($model->load($_POST) && $model->save()) {
             return $this->redirect(Url::previous());
         } elseif (!\Yii::$app->request->isPost) {
             $model->load($_GET);
         }
     } catch (\Exception $e) {
         $msg = isset($e->errorInfo[2]) ? $e->errorInfo[2] : $e->getMessage();
         $model->addError('_exception', $msg);
     }
     return $this->render('create', ['model' => $model]);
 }
Пример #9
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())) {
         $parent = Category::findOne($model->parent_id);
         if (!empty($parent)) {
             $model->indent = $parent->indent + 1;
         } else {
             $model->indent = 0;
         }
         $model->save();
         return $this->redirect(['index']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #10
0
 public function actionIndex()
 {
     if (Yii::$app->request->get('id')) {
         $model = Category::findOne(Yii::$app->request->get('id'));
     } else {
         $model = new Category();
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             Yii::$app->session->setFlash("success", "Update Category Successful");
             return $this->refresh();
         }
     }
     $items = Category::find()->where(['parent_id' => null])->all();
     return $this->render("index", ['model' => $model, 'items' => $items]);
 }
Пример #11
0
 public function actionAddCategory()
 {
     $user = Yii::$app->user->identity;
     if ($user->role == User::ROLE_ADMIN) {
         $model = new Category();
         $image = new Image();
         $model->load(Yii::$app->request->post(), '');
         $image->img = UploadedFile::getInstancesByName("image");
         if ($image->validate() && $model->save()) {
             if (!empty($image->img)) {
                 $image->uploads($model, Image::CATEGORY_STATUS);
             }
             return $model;
         }
         return array_merge($model->getErrors(), $image->getErrors());
     }
     return "Access denied";
 }
 /**
  * @param $userId
  *
  * @return bool
  * @throws \yii\db\Exception
  */
 public static function createBaseCategoryForUser($userId)
 {
     $transaction = Yii::$app->getDb()->beginTransaction();
     try {
         $categoryBases = CategoryBase::find()->all();
         /** @var CategoryBase $categoryBase */
         foreach ($categoryBases as $categoryBase) {
             $category = new Category();
             $category->title = $categoryBase->name;
             $category->user_id = $userId;
             $category->base_category_id = $categoryBase->id;
             $category->save();
         }
         $transaction->commit();
     } catch (\Exception $e) {
         $transaction->rollback();
         return false;
     }
 }
Пример #13
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 (!$this->is_access('category/create')) {
         Yii::$app->session->setFlash('error', $this->errorInfo);
         return $this->redirect($this->redirectUrl);
     }
     $model = new Category();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         // 加入分类推荐
         $CatRecommend = new CatRecommend();
         $CatRecommend->insertRecommend($model->cat_id, $_POST['Category']['recommend_type']);
         // 是否需要显示在导航栏
         if ($model->show_in_nav == 1) {
             $Nav = new Nav();
             $Nav->addData('c', $model->cat_id);
         }
         Yii::$app->session->setFlash('success', '添加成功');
         return $this->redirect(['index']);
     } else {
         Yii::$app->view->params['meta_title'] = '添加分类';
         $catList = $model->parent(0);
         return $this->render('create', ['model' => $model, 'catList' => $catList]);
     }
 }
Пример #14
0
 /**
  * Save Category model
  * @param bool $insert
  */
 public function saveCategory($insert = true)
 {
     $category = new Category();
     if ($this->item_id) {
         $category->id = $this->item_id;
     }
     $category->isNewRecord = $insert;
     $category->attributes = $this->toArray();
     $category->main = is_array($this->boxes) && in_array(self::PROPERTY_MAIN, $this->boxes) ? 1 : 0;
     $category->public = is_array($this->boxes) && in_array(self::PROPERTY_PUBLIC, $this->boxes) ? 1 : 0;
     $category->active = is_array($this->boxes) && in_array(self::PROPERTY_ACTIVE, $this->boxes) ? 1 : 0;
     $category->save();
 }