/** * Creates a new MenuItem model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($id) { $model = new MenuItem(); $parent = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if (!$model->parent) { $model->appendTo($parent); } else { $parent = $this->findModel($model->parent); $model->appendTo($parent); } Yii::$app->cache->flush(); return $this->redirect(['index', 'id' => $id]); } else { return $this->render('create', ['model' => $model, 'children' => $this->findModel($id)->children]); } }