I am a newbie to Yii, have learned for months. Recently i try to make a system using it. Everything almost be done. I run into a problem in implementing RBAC. I never before get touched with this kind of hierarchy. Followed the guide in the documentation. But it just doesn’t work properly. I’ll get to the point.
Two types of user: ‘author’, ‘admin’. Which column in the user table is ‘credential’.
I have a model named with ‘Patient’.
Patient Controller Access Rules for Admin
array('allow', // allow admin user to perform 'admin' and 'delete' actions 'actions'=>array('admin','delete'), 'users'=>array('@'), 'roles'=>array('admin'), ),
$auth=Yii::app()->authManager; $auth->createOperation('createPatient','create a patient'); $auth->createOperation('readPatient','read a patient'); $auth->createOperation('updatePatient','update a patient'); $auth->createOperation('deletePatient','delete a patient'); $bizRule='return Yii::app()->user->department==$params["patient"]->department'; $task=$auth->createTask('updateOwnPatient','update a patient by author himself',$bizRule); $task->addChild('updatePatient'); $role=$auth->createRole('author'); $role->addChild('createPatient'); $role->addChild('readPatient'); $role->addChild('updateOwnPatient'); $role=$auth->createRole('admin'); $role->addChild('author'); $role->addChild('deletePatient'); $role->assign('admin',1);//1 is user admin id.
When i go to admin page of patient with user admin. I am denied. Error 403 arise:You are not authorized to perform this action.
I’m blocked with this feature, may not go further before i get understood the fundamental.
Is there anyone who master RBAC in yii can help me out?
Appreciate all you guys!