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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...