Doubts about Yii2 RBAC

后端 未结 5 2068
情歌与酒
情歌与酒 2021-02-20 07:50

I\'ve been developing web apps using Yii 1.1.14 so far, but now it\'s time for an upgrade.

The company where I work has developed its own Access Control system, and I wa

5条回答
  •  不知归路
    2021-02-20 08:17

    I use it in one of the simplest method,I use them in the behaviours of my controller.

     public function behaviors()
        {
    
            return [
                'access' => [
                    'class' => \yii\filters\AccessControl::className(),
                    'rules' => [
                        [
                            'allow' => true,
                            'roles' => ['sysadmin'],
                            'actions' => ['index','view','update'],
                        ],
                        [
                            'allow' => true,
                            'roles' => ['staff'],
                            'actions' => ['index','create','update','view'],
                        ],
                    ],
                ],
            ];
    
        }
    

    Here roles are the one created in the auth-item table in the database and they have been assigned for users in auth-assignment table. In the behaviours we just use it as above. In the above code sysadmin can have access to index, view and update action, whereas staff can have access to index,create, update and view action.

提交回复
热议问题