Jump to content
Larry Ullman's Book Forums

Dynamic Logout Withyii


Recommended Posts

Hi Larry,

 

I have a quick (hopefully) question for you, what is the best way to perform dynamic login/logout links with Yii? I.e once you're logged in show "Logout User's name" but if you're not logged in show "Login".

 

Currently I have this code inside my main.php

  'id'=>('menu'),
  'items'=>array(
  /* Menu links go here*/
   array('label'=>'Create Account', 'url'=>array('/site/contact'), 'itemOptions'=> array('id'=>'sign_up'), 'active'=>false),
   array('label'=>'Sign in', 'url'=>array('/site/login'), 'itemOptions'=> array('id'=>'sign_in'), 'active'=>false, 'visible'=>Yii::app()->user->isGuest),
   array('label'=>'Logout ('.Yii::app()->user->firstName.')', 'url'=>array('/site/logout'), 'itemOptions'=> array('id'=>'sign_in'), 'active'=>false, 'visible'=>!Yii::app()->user->isGuest) 

 

As you can see I am showing the sign in link if the user->isGuest.

 

However if the user is not a guest I show the logout link. My problem is that if I am not logged in this fails because Yii::app()->user->firstName doesn't exist as I set this (setState) at login. What is the best way to achieve personalised dynamic login/logout links within Yii?

 

Thanks

 

Jonathon

Link to comment
Share on other sites

 Share

×
×
  • Create New...