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


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


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

hi, go to this link

See the following code…



$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);
























This link also help you…

Thank you very much,I will try,


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