Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set returnUrl value in Yii

Tags:

php

returnurl

yii

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?

like image 656
Let me see Avatar asked Nov 30 '13 10:11

Let me see


2 Answers

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.

like image 102
Keilo Avatar answered Sep 23 '22 10:09

Keilo


For those using Yii2

Yii::$app->user->returnUrl = Yii::$app->request->referrer;
like image 6
Jap Mul Avatar answered Sep 20 '22 10:09

Jap Mul