Browse Source

Refactored redirect() methods.

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
21eab82413
  1. 5
      framework/yii/web/Controller.php
  2. 8
      framework/yii/web/Response.php
  3. 3
      framework/yii/web/User.php

5
framework/yii/web/Controller.php

@ -9,6 +9,7 @@ namespace yii\web;
use Yii;
use yii\base\InlineAction;
use yii\helpers\Html;
/**
* Controller is the base class of Web controllers.
@ -95,7 +96,7 @@ class Controller extends \yii\base\Controller
* Redirects the browser to the specified URL.
* 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
* (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
@ -106,7 +107,7 @@ class Controller extends \yii\base\Controller
*/
public function redirect($url, $statusCode = null)
{
return Yii::$app->getResponse()->redirect($url, $statusCode);
return Yii::$app->getResponse()->redirect(Html::url($url), $statusCode);
}
/**

8
framework/yii/web/Response.php

@ -563,9 +563,9 @@ class Response extends \yii\base\Response
* return Yii::$app->getResponse()->redirect($url);
* ~~~
*
* @param array|string $url the URL to be redirected to. [[\yii\helpers\Html::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.
* @param string $url the URL to be redirected to. This can be a URL or an alias of the URL.
* The URL can be either relative or absolute. If relative, the host info of the current request
* will be prepend to the URL.
* @param integer $statusCode the HTTP status code. If null, it will use 302
* for normal requests, and [[ajaxRedirectCode]] for AJAX requests.
* See [[http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html]]
@ -574,7 +574,7 @@ class Response extends \yii\base\Response
*/
public function redirect($url, $statusCode = null)
{
$url = Html::url($url);
$url = Yii::getAlias($url);
if (strpos($url, '/') === 0 && strpos($url, '//') !== 0) {
$url = Yii::$app->getRequest()->getHostInfo() . $url;
}

3
framework/yii/web/User.php

@ -283,8 +283,7 @@ class User extends Component
$this->setReturnUrl($request->getUrl());
}
if ($this->loginUrl !== null) {
$response = Yii::$app->getResponse();
$response->redirect($this->loginUrl)->send();
Yii::$app->getResponse()->redirect($this->loginUrl)->send();
exit();
} else {
throw new HttpException(403, Yii::t('yii', 'Login Required'));

Loading…
Cancel
Save