Difference between #1 and #2 of
Simple RBAC

Revision #2 has been created by hasanavi on Apr 29, 2012, 10:16:22 PM with the memo:

grammar
« previous (#1) next (#5) »

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

If you are the one who needs simple Role based access control without the long RBAC process then this article is just for you. Lets jump to the point. On your user table make a column namesd 'roles' When you add users under roles you can assign them different roles like 'Admin' / 'user' / 'staff' etc etc. On your User Identity.php file write something like..
 


```php
[...]
Now, make a Utils.php file under protected/components directory and implement a simple Role check function based on how many roles you have.


 


```php
[...]
```

Here I just protect my AdminController.php from
unauthorised accessother roles than Admin. Basically from AdminController.php file accessRules() function it checks the users Roles written in Utils.php file. You can also use 1just one menu for all users based upon different roles. for example
 
 

```php
<?php $this->widget('zii.widgets.CMenu',array(
'items'=>array(
array('label'=>'Users', 'url'=>array('/manageUser/admin'), 'visible'=>Utils::isAdmin()),
array('label'=>'Ideas', 'url'=>array('/manageIdea/admin'), 'visible'=>Utils::isAdmin()),
[...]
33 1
43 followers
Viewed: 96 142 times
Version: 1.1
Category: Tutorials
Written by: hasanavi
Last updated by: Stageline
Created on: Apr 29, 2012
Last updated: 5 years ago
Update Article

Revisions

View all history