Difference between #5 and #8 of
Simple RBAC

Changes

Title unchanged

Simple RBAC

Category unchanged

Tutorials

Yii version unchanged

Tags unchanged

Simple RBAC, Role based access control, roles, Authentication, Role based menu

Content changed

[...]
),
```

*Sidenote:*
[CWebUser::checkAccess()] usually connects to the authorization system loaded in Yii.
Here we are replacing it with a simple system that just deals with roles instead of the hierarchical system defined by the derivatives of [CAuthManager]. See the official tutorial, [
Role-Based Access Control](http://www.yiiframework.com/doc/guide/1.1/en/topics.auth#role-based-access-control](Role-Based Access Control) for details.

## Checking permissions: usage
[...]
return array(
array('allow',
'action
s'=>array('admin'),
'roles'=>array('staff', 'devel'),
),
[...]
Here the "admin" action of the controller has restricted access: only those with roles "staff" or "devel" can access it.

As described in the API doc of [
CAccessRule](http://www.yiiframework.com/doc/api/1.1/CAccessRule#roles-detail](CAccessRule), the "roles" attribute will in fact call `Yii::app()->user->checkAccess()`.

### How to display a different menu according to roles
[...]
$this->widget('zii.widgets.CMenu',array(
'items'=>array(
array('label'=>'Users', 'url'=>array('/manageUser/admin'), 'visible'=>$user->checkAcces
s('staff')), array('label'=>'Your Ideas', 'url'=>array('/userarea/ideaList'), 'visible'=>$user->checkAccess('normal')),
array('label'=>'Login', 'url'=>array('/site/login'), 'visible'=>$user->isGuest),
array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!$user->isGuest)
),
));
?>
[...]
33 1
43 followers
Viewed: 120 341 times
Version: 1.1
Category: Tutorials
Written by: hasanavi
Last updated by: Stageline
Created on: Apr 29, 2012
Last updated: 12 years ago
Update Article

Revisions

View all history