/**
  * Creates a new Categories model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Categories();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->session->setFlash('success', "Category successfully Created");
         return $this->redirect(['view', 'id' => $model->categoryId]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Categories model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('createCategory')) {
         $model = new Categories();
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->idcategory]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         throw new ForbiddenHttpException();
     }
 }
 public function actionCategories()
 {
     $model = new Categories();
     $categories = Categories::find()->all();
     $categories_roots = Categories::find()->roots()->all();
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->user->can('createPost') && $model->addCategory()) {
             Yii::$app->getSession()->addFlash('success', '<b>Категория успешно добавлена!</b>');
         } else {
             Yii::$app->getSession()->addFlash('error', '<b>Произошла ошибка. Запись не добавлена</b>');
         }
     }
     return $this->render('categories', ['categories' => $categories, 'roots' => $categories_roots, 'model' => $model]);
 }