From 2c30ddfcb0621e74552e7f6628cb092f666c5709 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Tue, 1 Oct 2013 20:01:14 +0200 Subject: [PATCH] added web\Controller::goBack() as shortcut goBack() will redirect user to his returnUrl fixes #925 --- apps/basic/controllers/SiteController.php | 2 +- framework/yii/web/Controller.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/basic/controllers/SiteController.php b/apps/basic/controllers/SiteController.php index 1196280..e243223 100644 --- a/apps/basic/controllers/SiteController.php +++ b/apps/basic/controllers/SiteController.php @@ -61,7 +61,7 @@ class SiteController extends Controller { $model = new LoginForm(); if ($model->load($_POST) && $model->login()) { - return $this->goHome(); + return $this->goBack(); } else { return $this->render('login', array( 'model' => $model, diff --git a/framework/yii/web/Controller.php b/framework/yii/web/Controller.php index 6b8afa4..7509186 100644 --- a/framework/yii/web/Controller.php +++ b/framework/yii/web/Controller.php @@ -146,6 +146,19 @@ class Controller extends \yii\base\Controller } /** + * Redirects the browser to the last visited page. + * @param string|array $defaultUrl the default return URL in case it was not set previously. + * If this is null and the return URL was not set previously, [[Application::homeUrl]] will be redirected to. + * Please refer to [[User::setReturnUrl()]] on accepted format of the URL. + * @return Response the current response object + * @see User::getReturnUrl() + */ + public function goBack($defaultUrl = null) + { + return Yii::$app->getResponse()->redirect(Yii::$app->getUser()->getReturnUrl($defaultUrl)); + } + + /** * Refreshes the current page. * This method is a shortcut to [[Response::refresh()]]. * @param string $anchor the anchor that should be appended to the redirection URL.