0

我正在设计一个系统,但我需要赋予管理员用户创建角色并为其分配一组权限的权力。

目前在 RBAC

public function behaviors()
{
    return [
        'access' => [
            'class' => AccessControl::className(),
            'rules' => [
                [
                    'actions' => ['index','view'], // these action are accessible 
                                                   //only the yourRole1 and yourRole2
                    'allow' => true,
                    'roles' => ['yourRole1', 'yourRole2'],
                ],
                [    // all the action are accessible to superadmin, admin and manager
                    'allow' => true,  
                    'roles' => ['superAdmin', 'admin', 'manager'],
                ],   
            ],
        ],
    ];
}

然而,我最需要的是

public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
                'rules' => [
                    [
                        'actions' => ['index','view'], 
                        'allow' => true,
                        'permission' => ['canView'],
                    ],
                    [    
                        'actions' => ['update','delete'], // these action are accessible 
                        'allow' => true,  
                        'permission' => ['canDelete', 'canUpdate'],
                    ],   
                ],
            ],
        ];
    }

通过这样做并创建一组权限,管理员用户可以创建角色、分配权限并将角色分配给用户。

有谁知道这样做的 yii2 软件包?

4

1 回答 1

0

您正在使用的 AccessControl 过滤器已经允许您通过“权限”字段执行此操作。

[
    'actions' => ['index','view'], 
    'allow' => true,
    'permissions' => ['canView'],
],

查看文档: http ://www.yiiframework.com/doc-2.0/yii-filters-accessrule.html# $permissions-detail

于 2017-11-12T17:35:12.303 回答