Yii Framework Forum: Rbac Dynamic Menus - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Rbac Dynamic Menus Rate Topic: -----

#1 User is offline   AussieNeil 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 25-January 13

Posted 13 February 2013 - 01:30 AM

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
1

#2 User is offline   yan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 29-March 11
  • Location:Russia, Ufa

Posted 13 February 2013 - 02:39 AM

View PostAussieNeil, on 13 February 2013 - 01:30 AM, said:



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')

2

#3 User is offline   yasen 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 28
  • Joined: 29-October 11
  • Location:Sofia, Bulgaria

Posted 13 February 2013 - 02:39 AM

Yes, you will need to use the element 'visible'. Here's a link to The Guide http://www.yiiframew...ation-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...
0

#4 User is offline   AussieNeil 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 25-January 13

Posted 13 February 2013 - 05:36 AM

Thanks Yan. That was the solution, knew it would be something simple.

View Postyan, on 13 February 2013 - 02:39 AM, said:

'visible'=>	Yii::app()->user->checkAccess('Secretary')


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users