RBAC - set multiple roles for user?

I’m working on an application where a user can have one or many of three roles, a ‘superadmin’, an ‘admin’, and a ‘volunteer’. They have access to different (sometimes overlapping) role functions.

I was having a hard time understand the documentation for RBAC. My guess is that we manually set roles in the UserIdentity class, like

$this->setState('role', $user->is_admin);

Is it possible, using this system, to assign multiple roles to a logged in user? If so, how?.. does checkAccess() automatically look at Yii::app()->user->role? I’m not sure how assigning multiple roles would work if it does. We can’t keep reassigning a role to user->role, or it will overwrite - can we set it as an array? Will checkAccess() look through the array?

With Yii RBAC, you may have your 3 roles superadmin, admin, volunteer. To give admin volunteer role, simply make volunteer a child of admin. If you make admin a child of superadmin, then the user who is a superadmin will also be an admin. With that setup, i’m not sure if you need to make volunteer a child of superadmin for superadmin to have volunteer role or it is already a volunteer since its child admin is a volunteer. You can experiment with that little part and find out.

So… where specifically would I make a volunteer a child of admin? In UserIdentity, using setState(), if $user->admin and $user->volunteer are both true?

Each of the three roles can exist independent of each other - for example, a superadmin can do completely different things than an admin, and an admin can’t do many of the things a volunteer can. I don’t think I explained that clearly in the first post, so does this parents/child hierarchy still apply?

Thanks for the help, by the way :)

yes it still applies.

read the RBAC section http://www.yiiframework.com/doc/guide/topics.auth near the bottom of the page


it may help

Ah, that’s exactly what I was looking for. Thanks!


You can find another way to set user role on ,