Set Roles-Permissions For Users

Hi all,

I am creating a tool for reading, writing and deleting contents.

I have certain permissions (read, write, delete) for each role;

for example, admin is a role that has read,write and delete permissions.

so each user in my tool belongs to a role.

how can yii2 help me to set the permissions when the user logged in so he only can do what he is allowed according to his role.

I am using function behavior to set permissions as bellow:

public function behaviors() {

        return [

            'access' => [

                'class' => \yii\filters\AccessControl::className(),

                'rules' => [


                        'actions' => [

                            'delete', 'read','write'],

                        'allow' => true,

                        'roles' => ['@'],






but here all logged in users are allowed to these actions, so i need to set the actions according to his role??

can anyone help me ?

You need to implement RBAC, check this documentation

And this quick tutorial

Thank u for ur help,

I read the documentation, but what i want to ask is that should i call the permissions from DB every time I want to check on the user permissions?, or only when he logged in (only once)??