how to get to the previous page?


after logging in I wont my user to be directed to the previous page. It should be that by default, since the SiteController’s redirect is set to Yii::app()->user->returnUrl. But somehow the returnUrl just has “” and not the complete url. I maybe could use $_SERVER[‘HTTP_REFERER’] but I was wondering if there is some Yii method I could use…



It would be nice. Someone knows?

Yii provide url functions that allow you to get previous page:

If you don refresh the page, or not submit the page, then


will return your previous page url.

So you can use below code in your controller to get back to previous page


But in most case you do need submit the page, and deal with something then return to previous page. In this case you need use session to store return URL.

You need below request functions



First, you need store the return URL in the page you want to return

public function actionIndex()






$this->render('index', array(...));


Then in the next page, you can add below sentence after you complete the process.


//if status updated, redirect to previous page




$current_user will help you to identify the exactly page you want to return if there are many users working on the same page, and also they have different query script.

for example:

user A is working on this page

user B is working on another page分页的情况下-更新后,怎么返回上一页/page__gopid__238889#entry238889

They all have same "forum/index.php/topic/" but different parameters, in this case you need use $current_user to help them to get back what the page they were.