I have installed rights as suggested by most people, its easy to implement Role based access control. but I am stuck at a problem..
I need to assign a user a role from admin, who can change their roles..etc..
As rights doesn't create models for the tables I cant insert in them..and as such there is no documentation, how to do it...
First you need a drop-down of all roles in the system, for admin to select..
<?php
if (Yii::app()->user->isSuperuser) {
$all_roles=new RAuthItemDataProvider('roles', array(
'type'=>2,
));
$data=$all_roles->fetchData();
?>
<div>
<label for="type_id">Type</label>
<?php echo CHtml::dropDownList("Type",'',CHtml::listData($data,'name','name'));? >
</div>
<?php
}
?>
And then on backend you'll need to asign a role to the user based on the Type values selected by the admin...
if(Yii::app()->user->isSuperuser)
$type=$_POST['Type'];
else
$type='User';
$authorizer = Yii::app()->getModule("rights")->authorizer;
$authorizer->authManager->assign($type, $model->id);
This code checks if the registration was from admin, then it sets the role selected by the admin, else it sets User
as role, ie, same code will work for admin user create and normal signup
..
There are such other issues in Rights which are not preperly documented...I have written some in my blog.. My blog post about Yii Rights