Hi,
I have RBAC installed and working for individual pages.
I am using yii-Bootstrap to generate my menus.
I want to have Menu options based on Roles.
So within the items for TbNavBar I have this:
array('label'=>'Guest', 'visible'=>Yii::app()->user->isGuest, 'url'=>'#', 'items'=>array(
array('label'=>'Shows', 'url'=>array('/show/view')),
array('label'=>'Register', 'url'=>array('/site/registration')),
which works for people not signed in.
I want to do something similar for a user signed in who has the role of Secretary such as the menu is:
array('label'=>'Secretary', 'url'=>'#', 'items'=>array(
array('label'=>'Classes', 'url'=>array('/Section/admin')),
array('label'=>'Shows', 'url'=>array('/Show/admin')),
Now I know I need to add a ‘visible’ element, as done above, but do I need to write a function to do this or is there an RBAC function already that I can call?
Or is there something that I am missing.
Regards,
Neil
yan
(Yaroslav)
February 13, 2013, 7:39am
2
AussieNeil:
Now I know I need to add a ‘visible’ element, as done above, but do I need to write a function to do this or is there an RBAC function already that I can call?
Or is there something that I am missing.
Regards,
Neil
'visible'=> Yii::app()->user->checkAccess('Secretary')
yasen
(Yasenpetrov)
February 13, 2013, 7:39am
3
Yes, you will need to use the element ‘visible’. Here’s a link to The Guide http://www.yiiframework.com/doc/guide/1.1/en/topics.auth#defining-authorization-hierarchy
$auth=Yii::app()->authManager;
$auth->createOperation('createPost','create a post');
$auth->createOperation('readPost','read a post');
$auth->createOperation('updatePost','update a post');
$auth->createOperation('deletePost','delete a post');
$bizRule='return Yii::app()->user->id==$params["post"]->authID;';
$task=$auth->createTask('updateOwnPost','update a post by author himself',$bizRule);
$task->addChild('updatePost');
$role=$auth->createRole('reader');
$role->addChild('readPost');
$role=$auth->createRole('author');
$role->addChild('reader');
$role->addChild('createPost');
$role->addChild('updateOwnPost');
$role=$auth->createRole('editor');
$role->addChild('reader');
$role->addChild('updatePost');
$role=$auth->createRole('admin');
$role->addChild('editor');
$role->addChild('author');
$role->addChild('deletePost');
$auth->assign('reader','readerA');
$auth->assign('author','authorB');
$auth->assign('editor','editorC');
$auth->assign('admin','adminD');
Then use business rules to check for access:
$bizRule='return !Yii::app()->user->isGuest;';
$auth->createRole('authenticated', 'authenticated user', $bizRule);
$bizRule='return Yii::app()->user->name === "admin";';
$auth->createRole('admin', 'admin user', $bizRule);
Edit: Not quite sure how much this helps, but this is where you will need to be looking at…
Thanks Yan. That was the solution, knew it would be something simple.