/** * Creates a new Category model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $post = Yii::$app->request->post(); $model = new Category(); // Если пост получен и загружен. if ($model->load($post)) { // Если передан ID родительской категории. if (isset($post['parent_category_id']) && !empty($post['parent_category_id'])) { $parentCategoryId = (int) $post['parent_category_id']; $parentCategory = Category::findOne($parentCategoryId); if ($model->prependTo($parentCategory)) { return $this->redirect(['index']); } return $this->render('create', ['model' => $model]); } // Создание новой корневой категории. if ($model->makeRoot()) { return $this->redirect(['index']); } return $this->render('create', ['model' => $model]); } else { return $this->render('create', ['model' => $model]); } }