Browse Source

Fixes #826: cleaned up User::getReturnUrl().

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
30907b6134
  1. 21
      framework/yii/web/User.php

21
framework/yii/web/User.php

@ -10,6 +10,7 @@ namespace yii\web;
use Yii; use Yii;
use yii\base\Component; use yii\base\Component;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
/** /**
* User is the class for the "user" application component that manages the user authentication status. * User is the class for the "user" application component that manages the user authentication status.
@ -255,20 +256,34 @@ class User extends Component
* This property is usually used by the login action. If the login is successful, * This property is usually used by the login action. If the login is successful,
* the action should read this property and use it to redirect the user browser. * the action should read this property and use it to redirect the user browser.
* @param string|array $defaultUrl the default return URL in case it was not set previously. * @param string|array $defaultUrl the default return URL in case it was not set previously.
* If this is null, it means [[Application::homeUrl]] will be redirected to. * If this is null and the return URL was not set previously, [[Application::homeUrl]] will be redirected to.
* Please refer to [[\yii\helpers\Html::url()]] on acceptable URL formats. * Please refer to [[setReturnUrl()]] on accepted format of the URL.
* @return string the URL that the user should be redirected to after login. * @return string the URL that the user should be redirected to after login.
* @see loginRequired * @see loginRequired
*/ */
public function getReturnUrl($defaultUrl = null) public function getReturnUrl($defaultUrl = null)
{ {
$url = Yii::$app->getSession()->get($this->returnUrlVar, $defaultUrl); $url = Yii::$app->getSession()->get($this->returnUrlVar, $defaultUrl);
if (is_array($url)) {
if (isset($url[0])) {
$route = array_shift($url);
return Yii::$app->getUrlManager()->createUrl($route, $url);
} else {
$url = null;
}
}
return $url === null ? Yii::$app->getHomeUrl() : $url; return $url === null ? Yii::$app->getHomeUrl() : $url;
} }
/** /**
* @param string|array $url the URL that the user should be redirected to after login. * @param string|array $url the URL that the user should be redirected to after login.
* Please refer to [[\yii\helpers\Html::url()]] on acceptable URL formats. * If an array is given, [[UrlManager::createUrl()]] will be called to create the corresponding URL.
* The first element of the array should be the route, and the rest of
* the name-value pairs are GET parameters used to construct the URL. For example,
*
* ~~~
* array('admin/index', 'ref' => 1)
* ~~~
*/ */
public function setReturnUrl($url) public function setReturnUrl($url)
{ {

Loading…
Cancel
Save