RBAC tables in yii2

  1. How to create permissions, roles and rules in yii2 using gii?

  2. How to assign roles in yii2?

How to implement all these using below 4 tables?

  1. auth_item

  2. auth_item_child

  3. auth_assignment

  4. auth_rule

Consider the case:

There are two users Admin and FieldOfficer:

I have SHGProfile CRUD application.

FieldOfficer can access only create and view actions in SHGProfile. Whereas Admin can access all create, view, update and delete actions.

Here Roles are Admin and FieldOfficer. Permissions are createGroup, viewGroup, updateGroup, and deleteGroup

Here in which table we need to create Roles and Permissions and how to assign it to user?

The easiest way to go is to create a command which creates all your roles and permissions. You can find an example in the Yii2 Guide under Authorization->Building Authorization Data, or have a look at my script attached.