【发布时间】:2017-11-11 21:14:36
【问题描述】:
我正在设计一个系统,但我需要授权管理员用户创建角色并为其分配一组权限。
目前在 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 的包可以做到这一点?
【问题讨论】:
-
你试过Yii2中默认的rbac组件吗???