[how to?] RBAC limiting queries

Hello all, I’m quite new in Yii/Yii2 and I’m still adapting/learning so please bare with me.

I think I understand how RBAC works, but I’ve searched and didn’t find any useful link/answer to my “problem”.

Can I use RBAC to limit access to, lets say categories?

And If yes how to approach it?


admin can see/edit/post all posts no matter witch category they are related

user 1 can only see/edit/post in category fruits

user 2 can see/edit/post in categories fruits and vegetables


ps: sorry about my English

regards, Motorui

You could add a numerical index to the database table of categories. If your RBAC is not numerical, you could create an array of the roles with numerical indices i.e. [3] => ‘admin’, [2] = > ‘user2’, [1] => ‘user1’. Then check if this number is greater than or equal to the number from the category table.

Thanks, I’ll try with something like that, but I don’t think it will work perfectly…

For instants: if I want to give permissions to a user only to categories 1 and 6 and not to 2-5?

Regards, Motorui