Getattribute() On A Non-Object

In my layouts/main.php: Fatal error: Call to a member function getAttribute() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/cresearch/protected/views/layouts/main.php on line 38

When the user is logged in the Menu correctly displays first_name. When logged out there is an error b/c ‘first_name’ is not an object. Please advise.




<?php $this->widget('bootstrap.widgets.TbNavbar',array(

  'class'=>'bootstrap.widgets.TbMenu',

  'items'=>array(    

    array('label'=>Yii::app()->getModule('user')->t("Account").'('.Yii::app()->getModule('user')->user()->profile->

    getAttribute('first_name').')', 'visible'=>!Yii::app()->user->isGuest, 'items'=>array(



The way I fixed this issue was by adding another menu for non-logged in users. If there’s a better way, please inform.




if (!Yii::app()->user->isGuest)

{

    // Menu for logged users

    $this->widget('bootstrap.widgets.TbNavbar',array(

        'items'=>array(

                ...

        ),

    )); 

}

else

{

    // Menu for non logged users

    $this->widget('bootstrap.widgets.TbNavbar',array(

        'items'=>array(

                ...

        ),

    ));

}