Yii framework RBAC part 2
In my previous post I talked about setting up a right structure. In this post I will show you how to use this data to control what user can and can't do.
...
First off you will need to assign roles to users in your application. You can use this by running the following code:
$auth = Yii::app()->authManager;
$auth->assign('role',1);
In this example 1 is the user id you wish to assign assign the role to. You will only need to run this piece of code once for every user. To revoke acces symply replace assign with revoke. The userid can be either a string or int depending on what you use for your application.
Once assigned You can check acces in 2 ways. The first is on controller level. you do this by adding accessrules. The second way is by checking with the following command:
if(Yii::app()->user->checkAccess('deletePost'))
This second way is required when you have to give parameters to the accessrule. You do this like such:
Yii::app()->user->checkAccess('deletePost',$params)
I hope you have enough information to work with CDbAuthManager after this. Please be sure to ask anything you need.
01/12/12 10:00:00 am,