Exemple #1
0
 /**
  * Creates a new Menu model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @param int $top_id
  * @return mixed
  */
 public function actionCreate($top_id = 0)
 {
     $model = new Menu();
     if (Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->post());
         if ($top_id) {
             $saved = $model->prependTo(Menu::findOne($top_id));
         } else {
             $saved = $model->makeRoot();
         }
         if ($saved) {
             Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Menu has been created.'));
             return $this->redirect(ReturnUrl::getUrl());
         }
     } else {
         $model->load(Yii::$app->request->get());
     }
     return $this->render('create', compact('model'));
 }