Commit 30907b61 by Qiang Xue

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

parent 6c6cb3cd
......@@ -10,6 +10,7 @@ namespace yii\web;
use Yii;
use yii\base\Component;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
/**
* 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,
* 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.
* If this is null, it means [[Application::homeUrl]] will be redirected to.
* Please refer to [[\yii\helpers\Html::url()]] on acceptable URL formats.
* If this is null and the return URL was not set previously, [[Application::homeUrl]] will be redirected to.
* Please refer to [[setReturnUrl()]] on accepted format of the URL.
* @return string the URL that the user should be redirected to after login.
* @see loginRequired
*/
public function getReturnUrl($defaultUrl = null)
{
$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;
}
/**
* @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)
{
......
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