How to set returnUrl value in yii

2019-05-05 21:11发布

I am using Yii and the problem i am getting is with the Yii::app()->user->returnUrl .It always returns me to the index.php page.

How can I set its value to the page which requested the current page as I do not know from which page user has visited the current page?

6条回答
贼婆χ
2楼-- · 2019-05-05 21:31

I created a Yii extension to manage return URLs, you can find it here: https://github.com/cornernote/yii-return-url#yii-returnurl

It's an improvement over the way Yii handles it because it stores the return url in the GET/POST data instead of the SESSION. This means that if you have multiple tabs open then each can have it's own return url.

查看更多
干净又极端
3楼-- · 2019-05-05 21:32

There is no such thing as: Yii::app()->user->urlReferrer

It should be: Yii::app()->request->urlReferrer or Yii::app()->request->requestUri (current page)

So try this:

Yii::app()->user->returnUrl = Yii::app()->user->urlReferrer;

Or this one (which I personally prefer):

Yii::app()->user->returnUrl = Yii::app()->request->requestUri;
查看更多
再贱就再见
4楼-- · 2019-05-05 21:34

For those using Yii2

Yii::$app->user->returnUrl = Yii::$app->request->referrer;
查看更多
可以哭但决不认输i
5楼-- · 2019-05-05 21:37

You can use like this

$http = new CHttpRequest();
$referrer_url = $http->getUrlReferrer();
$this->redirect($referrer_url);

Hope this will help you

查看更多
对你真心纯属浪费
6楼-- · 2019-05-05 21:43

You can use Yii::app()->request->urlReferrer to see where the user came from.

public function beforeAction()
{
    Yii::app()->user->returnUrl = Yii::app()->request->urlReferrer;
    return parent::beforeAction();
}

Be careful, if the user came from a 3rd party site, then this will redirect them away from your site.

查看更多
混吃等死
7楼-- · 2019-05-05 21:44

You can also do like that

Yii::app()->user->returnUrl = Yii::app()->request->urlReferrer;
$this->redirect(Yii::app()->user->returnUrl);
查看更多
登录 后发表回答