Commit 21eab824 by Qiang Xue

Refactored redirect() methods.

parent 2885d098
...@@ -9,6 +9,7 @@ namespace yii\web; ...@@ -9,6 +9,7 @@ namespace yii\web;
use Yii; use Yii;
use yii\base\InlineAction; use yii\base\InlineAction;
use yii\helpers\Html;
/** /**
* Controller is the base class of Web controllers. * Controller is the base class of Web controllers.
...@@ -95,7 +96,7 @@ class Controller extends \yii\base\Controller ...@@ -95,7 +96,7 @@ class Controller extends \yii\base\Controller
* Redirects the browser to the specified URL. * Redirects the browser to the specified URL.
* This method is a shortcut to [[Response::redirect()]]. * This method is a shortcut to [[Response::redirect()]].
* *
* @param array|string $url the URL to be redirected to. [[\yii\helpers\Html::url()]] * @param array|string $url the URL to be redirected to. [[Html::url()]]
* will be used to normalize the URL. If the resulting URL is still a relative URL * will be used to normalize the URL. If the resulting URL is still a relative URL
* (one without host info), the current request host info will be used. * (one without host info), the current request host info will be used.
* @param integer $statusCode the HTTP status code. If null, it will use 302 * @param integer $statusCode the HTTP status code. If null, it will use 302
...@@ -106,7 +107,7 @@ class Controller extends \yii\base\Controller ...@@ -106,7 +107,7 @@ class Controller extends \yii\base\Controller
*/ */
public function redirect($url, $statusCode = null) public function redirect($url, $statusCode = null)
{ {
return Yii::$app->getResponse()->redirect($url, $statusCode); return Yii::$app->getResponse()->redirect(Html::url($url), $statusCode);
} }
/** /**
......
...@@ -563,9 +563,9 @@ class Response extends \yii\base\Response ...@@ -563,9 +563,9 @@ class Response extends \yii\base\Response
* return Yii::$app->getResponse()->redirect($url); * return Yii::$app->getResponse()->redirect($url);
* ~~~ * ~~~
* *
* @param array|string $url the URL to be redirected to. [[\yii\helpers\Html::url()]] * @param string $url the URL to be redirected to. This can be a URL or an alias of the URL.
* will be used to normalize the URL. If the resulting URL is still a relative URL * The URL can be either relative or absolute. If relative, the host info of the current request
* (one without host info), the current request host info will be used. * will be prepend to the URL.
* @param integer $statusCode the HTTP status code. If null, it will use 302 * @param integer $statusCode the HTTP status code. If null, it will use 302
* for normal requests, and [[ajaxRedirectCode]] for AJAX requests. * for normal requests, and [[ajaxRedirectCode]] for AJAX requests.
* See [[http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html]] * See [[http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html]]
...@@ -574,7 +574,7 @@ class Response extends \yii\base\Response ...@@ -574,7 +574,7 @@ class Response extends \yii\base\Response
*/ */
public function redirect($url, $statusCode = null) public function redirect($url, $statusCode = null)
{ {
$url = Html::url($url); $url = Yii::getAlias($url);
if (strpos($url, '/') === 0 && strpos($url, '//') !== 0) { if (strpos($url, '/') === 0 && strpos($url, '//') !== 0) {
$url = Yii::$app->getRequest()->getHostInfo() . $url; $url = Yii::$app->getRequest()->getHostInfo() . $url;
} }
......
...@@ -283,8 +283,7 @@ class User extends Component ...@@ -283,8 +283,7 @@ class User extends Component
$this->setReturnUrl($request->getUrl()); $this->setReturnUrl($request->getUrl());
} }
if ($this->loginUrl !== null) { if ($this->loginUrl !== null) {
$response = Yii::$app->getResponse(); Yii::$app->getResponse()->redirect($this->loginUrl)->send();
$response->redirect($this->loginUrl)->send();
exit(); exit();
} else { } else {
throw new HttpException(403, Yii::t('yii', 'Login Required')); throw new HttpException(403, Yii::t('yii', 'Login Required'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment