Yii Framework Forum: Access roles - Yii Framework Forum

Jump to content

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

Access roles Rate Topic: -----

#1 User is offline   kitty10 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 139
  • Joined: 13-April 10

Posted 21 June 2010 - 03:16 AM

I have a problem ... my application has five roles to access ...
When I login I need to recognize the role of those who login and using this to show a different menu based on the initial roles ...
I create a function in class UserIdentity??
Help me....
0

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 21 June 2010 - 01:47 PM

For recognize the role you can use checkAcces().

In your menu you can write something like:

$user=Yii::app()->user();


if ($user->checkAccess('role1'))
   $items1=>array(),



in practice, you can build a different array according to your permissions.
0

#3 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 23 June 2010 - 04:02 AM

CMenu has a 'visible' property that lets you determine whether a menu item will be shown. Here's how the default generated webapp handles it for login/logout situations, you can do your visibility tests with checkAccess() as zaccaria mentioned.

<?php $this->widget('zii.widgets.CMenu',array(
	'items'=>array(
		array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>Yii::app()->user->isGuest),
		array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest)
	),
)); ?>

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