Browse Source

Refactored redirect() methods.

tags/2.0.0-beta
Qiang Xue 12 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;
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
* 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
*/ */
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);
} }
/** /**

8
framework/yii/web/Response.php

@ -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
*/ */
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;
} }

3
framework/yii/web/User.php

@ -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'));

Loading…
Cancel
Save