Пример #1
0
 /**
  * Create a menu item
  * @return array|string|Response
  */
 public function actionCreate($menu_id)
 {
     $model = new MenuItem();
     if (!$model->menu_id) {
         $model->menu_id = $menu_id;
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         } else {
             if ($model->save()) {
                 $this->flash('success', Yii::t('site', 'Menu item created'));
                 return $this->redirect(['/admin/' . $this->module->id . '/a/edit', 'id' => $model->menu_id]);
             } else {
                 $this->flash('error', Yii::t('easyii', 'Create error. {0}', $model->formatErrors()));
                 return $this->refresh();
             }
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }