/** * Creates a new Category model. * If creation is successful, the browser will be redirected to the 'view' page. * @param string|null $parentId * @param string|null $backUrl * @return mixed * @throws NotFoundHttpException */ public function actionCreate($parentId = null, $backUrl = null) { $model = new Category(); $model->loadDefaultValues(); $model->status = Category::STATUS_PUBLISHED; if (isset($parentId)) { $parentCategory = $this->findModel($parentId); $model->parent_id = $parentCategory->id; } if ($model->load(Yii::$app->request->post()) && $model->saveNode()) { return $this->redirect($backUrl ? $backUrl : ['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }