Reputation: 5755
I want to make a condition in displaying a menu item in CMenu by limiting it only to one user ,for example, with the name of 'admin'. I am writing this
'items'=>array(
array('label'=>'Logs','url'=>array('actionLogs/admin'),'icon'=>'wrench white',
'visible'=>!Yii::app()->user->isGuest),
This condition works fine. Next I try to complicate a little the condition of the visibility, but it fails at all
'items'=>array(
array('label'=>'Logs','url'=>array('actionLogs/admin'),'icon'=>'wrench white',
'visible'=>'!Yii::app()->user->isGuest && Yii::app()->user->name=="admin"'),
How can I achieve what I am trying to do? Thanks.
Upvotes: 1
Views: 5978
Reputation: 5755
Okay, found the solution. For those who will meet the same problem, here's the code:
'items'=>array(
array('label'=>'Logs','url'=>array('actionLogs/admin'),'icon'=>'wrench white',
'visible'=>(!Yii::app()->user->isGuest && Yii::app()->user->name=="admin")),
and force reload without caching.(Ctrl+F5)
Upvotes: 3