Beispiel #1
0
 /**
  * Создание корневой категории
  * @return string
  * @TODO добавление title
  */
 public function actionCreate()
 {
     $model = new Categories();
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->post('Categories')['rootCat'] === '') {
             $model = new Categories(['name' => Yii::$app->request->post('Categories')['name'], 'site_id' => Yii::$app->request->post('Categories')['site_id'], 'title' => Yii::$app->request->post('Categories')['title'], 'cssclass' => md5(time()), 'action' => Yii::$app->request->post('Categories')['action']]);
             $model->makeRoot();
         } else {
             $model = new Categories(['name' => Yii::$app->request->post('Categories')['name'], 'site_id' => Yii::$app->request->post('Categories')['site_id'], 'title' => Yii::$app->request->post('Categories')['title'], 'cssclass' => md5(time()), 'action' => Yii::$app->request->post('Categories')['action']]);
             $rootCategory = Categories::find()->where(['id' => Yii::$app->request->post('Categories')['rootCat']])->one();
             //var_dump(Yii::$app->request->post('Categories')); exit;
             $model->prependTo($rootCategory);
         }
         return $this->redirect(Url::toRoute('categories/index'));
     } else {
         return $this->render('_form', ['model' => $model]);
     }
 }