Search code examples
phpyiireturnurl

How to set returnUrl value in 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?


Solution

  • 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.