/** * 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('/backend/category/create', ['model' => $model]); } }