Search code examples
phpyii2rbac

Yii2 - RBAC, Difference between Roles and Permissions


How can I assign permission to specific user:

Role A

Permission A1

Permission A2

how can i say : if(Yii::$app->user->can('A1')){}


Solution

  • A role it is a symbolic value that is used to indicate a behavior and a set of actions (permissions) associated with this behavior. For example, a typical role is what distinguishes an administrator or a user who can only see (an observer),.

    A permission is the elementary level of action that is allowed to make. (edit, create or delete an object, for example).

    A role is associated with a user.

    So it is the administrator user is associated with the administrator role, while other user, for example, are associated with the role of observers rather than creators or modifiers.