stay on the same page after logout

I am having an issue to keep my application on the same page after logout.

I use


Yii::app()->user->logout(FALSE);

$this->refresh();

but it leads to the following browser error:

The page isn’t redirecting properly.

Anybody has an idea on how to tackle this situation please share.

Cheers,

bettor

Yeah, the SiteController > actionLogout() function needs to redirect to something. In essence, by clicking the link to log out, you’ve already navigated away from the previous page. I’m not sure the proper way to do this in any case, but I’m hoping there is a simple way in Yii. The general strategy that I use with my Drupal site is to have the logout link include a parameter for destination… ie: index.php?r=site/logout&dest=somewhere/else. Then, in actionLogout(), you can retrieve this get parameter. So like, for the part of your site where you display the logout link, add some code to set the destination to the current page. This is somewhat crud, I realize I don’t know the proper Yii method at the moment, but this might get you started. Anyone know the absolute best method here? I’d like to know as well.

Thanks

you are right…when the logout button is clicked the current action is changed with logout and after that Yii attempts to refresh the logout action and that’s going nowhere. I hope there is an Yii way to do that such as the returnUrl property but if there isn’t I guess I will have to develop a custom one

Create special function in CWebUser. Something like returnToReferrer(). If the referrer belongs to your site, redirect to it. Otherwise redirect to site/index.

I think I found it.




$this->redirect(Yii::app()->user->returnUrl);



Try this. Looks like it’s right. Got it from this page: http://www.yiiframework.com/doc/guide/form.action