alexcruzvb
(Alexcruzvb)
October 22, 2013, 12:19pm
1
Hi All,
I would appreciate if someone would show me the way to conditionally display a menu item depending on
the logged in users role? For example if the user is logged in as a regular user I do not want them to even see the
"manage members" menu link. Thanks in advance for your help. BTW I am new to Yii and it is really great!!
-Alex-
prat
(Yurfriend19)
October 22, 2013, 12:33pm
2
It can easily be done using ‘visible’ property and by defining roles in your controller. For example I don’t want normal authenticated users to see ‘List Users’ link only admin is allowed so I can have following
array('label'=>'List Users', 'icon'=>'list', 'url'=>array('/user/index'), 'visible'=>Yii::app()->user->checkAccess('admin')),
.
Further in controller I have
array('allow',
'actions'=>array('create', 'index'),
'roles'=>array('admin'),),
Here admin is role not username.
alexcruzvb
(Alexcruzvb)
October 22, 2013, 2:29pm
3
prat:
It can easily be done using ‘visible’ property and by defining roles in your controller. For example I don’t want normal authenticated users to see ‘List Users’ link only admin is allowed so I can have following
array('label'=>'List Users', 'icon'=>'list', 'url'=>array('/user/index'), 'visible'=>Yii::app()->user->checkAccess('admin')),
.
Further in controller I have
array('allow',
'actions'=>array('create', 'index'),
'roles'=>array('admin'),),
Here admin is role not username.
Thanks a million!! I will try that!