Yii Framework Forum: stay on the same page after logout - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

stay on the same page after logout Rate Topic: -----

#1 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 749
  • Joined: 02-February 09

Posted 16 February 2010 - 10:42 AM

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
0

#2 User is offline   Jaz Manister 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 27-October 09
  • Location:Rural Western New York, USA

Posted 16 February 2010 - 01:41 PM

View Postbettor, on 16 February 2010 - 10:42 AM, said:

Yii::app()->user->logout(FALSE);
$this->refresh();

but it leads to the following browser error:
The page isn't redirecting properly.


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
0

#3 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 749
  • Joined: 02-February 09

Posted 16 February 2010 - 02:52 PM

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
0

#4 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 16 February 2010 - 02:54 PM

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

#5 User is offline   Jaz Manister 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 109
  • Joined: 27-October 09
  • Location:Rural Western New York, USA

Posted 16 February 2010 - 02:55 PM

View Postbettor, on 16 February 2010 - 02:52 PM, said:

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


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.yiiframew...ide/form.action
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users