/** * Creates a new ProductCategory model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new ProductCategory(); $treeParents = TreeHelper::build($model->find()->addOrderBy('tree')->addOrderBy('lft')->all()); if ($model->load(Yii::$app->request->post())) { if (empty($model->parent_id)) { $model->makeRoot(); } else { $root = $model->findOne(['id' => $model->parent_id]); $model->appendTo($root); } return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model, 'treeParents' => $treeParents]); } }