Ejemplo n.º 1
0
 public function actionEdit($parent_id = null, $id = null)
 {
     if (null === $parent_id) {
         throw new NotFoundHttpException();
     }
     /** @var null|BackendMenu|HasProperties $model */
     $model = null;
     if (null !== $id) {
         $model = BackendMenu::findById($id);
     } else {
         if (null !== ($parent = BackendMenu::findById($parent_id))) {
             $model = new BackendMenu();
             $model->loadDefaultValues();
             $model->parent_id = $parent_id;
         } else {
             $model = new BackendMenu();
             $model->loadDefaultValues();
             $model->parent_id = 0;
         }
     }
     if (null === $model) {
         throw new ServerErrorHttpException();
     }
     $post = \Yii::$app->request->post();
     if ($model->load($post) && $model->validate()) {
         if ($model->save()) {
             Yii::$app->session->setFlash('success', Yii::t('app', 'Record has been saved'));
             $returnUrl = Yii::$app->request->get('returnUrl', ['/backend/backend-menu/index']);
             switch (Yii::$app->request->post('action', 'save')) {
                 case 'next':
                     return $this->redirect(['/backend/backend-menu/edit', 'returnUrl' => $returnUrl]);
                 case 'back':
                     return $this->redirect($returnUrl);
                 default:
                     return $this->redirect(Url::toRoute(['/backend/backend-menu/edit', 'id' => $model->id, 'returnUrl' => $returnUrl, 'parent_id' => $model->parent_id]));
             }
         } else {
             throw new ServerErrorHttpException();
         }
     }
     return $this->render('form', ['model' => $model]);
 }