How To Assign Permissions In Yii Rights

I need to assign permission at the time of user creation,Like controller/action. I assigned a Role to user now When user after login when go to


controller/action(user/profile) 

its show a error you are not authorized to perform this action. but when I go to rights module and assign this permission


controller/action

to this user,it is working, How I can add permission for this user automatically?

hi, go to this link

http://www.yiiframework.com/doc/guide/1.1/en/topics.auth#role-based-access-control

See the following code…




$auth=Yii::app()->authManager;

 

$auth->createOperation('createPost','create a post');

$auth->createOperation('readPost','read a post');

$auth->createOperation('updatePost','update a post');

$auth->createOperation('deletePost','delete a post');

 

$bizRule='return Yii::app()->user->id==$params["post"]->authID;';

$task=$auth->createTask('updateOwnPost','update a post by author himself',$bizRule);

$task->addChild('updatePost');

 

$role=$auth->createRole('reader');

$role->addChild('readPost');

 

$role=$auth->createRole('author');

$role->addChild('reader');

$role->addChild('createPost');

$role->addChild('updateOwnPost');

 

$role=$auth->createRole('editor');

$role->addChild('reader');

$role->addChild('updatePost');

 

$role=$auth->createRole('admin');

$role->addChild('editor');

$role->addChild('author');

$role->addChild('deletePost');

 

$auth->assign('reader','readerA');

$auth->assign('author','authorB');

$auth->assign('editor','editorC');

$auth->assign('admin','adminD');




This link also help you…

http://octathorpeweb.com/blog/2012/03/06/yii-rights-extension-rbac-role-based-access-control/

Thank you very much,I will try,

Hello,

Can you tell me please ,I am using Yii Rights and how I can set Permissions automatically?

I am adding a Role automatically but problem with permissions,I have’t any idea how I can set permissions?

Maybe you should get controller actions by ReflectionClass::getMethods() (or get_class_methods, or store controller actions in array). Then Yii::app()->authManager->createOperation(‘YourActionName’, …); And after you need to add operation to role