Simple RBAC

Comparing #1 with #2

Revision #2 was created by hasanavi hasanavi on Apr 29, 2012, 10:16:22 PM.

grammar

Content

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()),
[...]