Exemplo n.º 1
0
 /**
  * Updates an existing Redirect model.
  * If update is successful, the browser will be redirected to the 'redirect' page.
  * @param $id
  * @return string
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionUpdateRedirect($id)
 {
     /* @var $model Redirect */
     $model = Redirect::find()->where(['id' => $id])->one();
     if ($model !== null) {
         if ($model->load($_POST) && $model->validate()) {
             if ($model->save()) {
                 Yii::$app->session->setFlash('success', Yii::t('app', 'Records has been saved'));
                 $returnUrl = Yii::$app->request->get('returnUrl', ['redirect']);
                 switch (Yii::$app->request->post('action', 'save')) {
                     case 'next':
                         return $this->redirect(['create-redirect', 'returnUrl' => $returnUrl]);
                     case 'back':
                         return $this->redirect($returnUrl);
                     default:
                         return $this->redirect(Url::toRoute(['update-redirect', 'id' => $model->id, 'returnUrl' => $returnUrl]));
                 }
             }
         } else {
             return $this->render('updateRedirect', ['model' => $model]);
         }
     } else {
         throw new NotFoundHttpException('redirect #' . $id . ' not found');
     }
 }