Jonathon Posted April 24, 2013 Share Posted April 24, 2013 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 More sharing options...
Larry Posted April 26, 2013 Share Posted April 26, 2013 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 More sharing options...
Jonathon Posted April 26, 2013 Author Share Posted April 26, 2013 Thanks Larry, That was doing my head in. I was trying to place if(isset... statements in there which failed. Thanks Jonathon Link to comment Share on other sites More sharing options...
Recommended Posts