RBAC with user status

Hi everybody,

I have implemented a RBAC functionality and everything is working fine. The thing is, I want to add an additional condition to the access control. For example, I want the user to be role ‘admin’ and have a status of ‘active’ in order to access an action.

How can I achieve this?

Thanks in advance.

You can create a method on your user model to return the value of active status, then call it in an access control rule on the controller in matchCallback, something like:

'rules' => [


                        'actions' => ['index', 'view','create', 'update', 'delete'],

                        'allow' => true,

                        'roles' => ['@'],

                        'matchCallback' => function ($rule, $action) {

                            return PermissionHelpers::requireStatus('Active');





The PermissionHelpers class and requireStatus method used there is something I wrote as part of a helper class for this purpose, but that is specific to my project. But you could write a method that compares the current users status value to the value of active, along the same lines. If it returns true, it matches the callback and the action is allowed to continue. This way you do not have to affect your other RBAC. Hope this helps.

Thanks for your help, I think your approach is correct just by seeing your code. I’ll test tomorrow and let you know the result :) :) :)

Thanks again, it worked! :)

@xCarlosx glad I could help, I use that approach a lot. The behaviors method and architecture in Yii 2 is just awesome.