Jump to content
Larry Ullman's Book Forums

Preventing Property "Cwebuser.First_Name" Is Not Defined When Using Set State


Jonathon
 Share

Recommended Posts

Hi,

 

I've been using 

 

$this->setState('first_name', $user->first_name);

 

To set the first name of a user and use this value within a menu.

 

However when I try to hide the menu if the user isn't logged in I get the error message above in the title. Whcih I understand. I just don't know how to overcome this in Yii. Sure it's simple. If someone could help me out that would be great.

 

Here is the menu code.

 

 

...
code above
....
 
'buttons'=>array(
  array('visible'=> !Yii::app()->user->isGuest, 'label'=>Yii::app()->user->first_name, 'items'=>array(

 

This code works fine once logged in. Just not when a user is not logged in

 

Thanks

 

 

Link to comment
Share on other sites

I know exactly what you're talking about and have seen it myself before. A solution, which shouldn't seem necessary but is, would be to wrap the 'label' value in an isset():

'label' => (isset(Yii::app()->user->first_name) ? Yii::app()->user->first_name : 'Greetings')
Link to comment
Share on other sites

 Share

×
×
  • Create New...