【问题标题】:Yii2 yii2mod/yii2-rbacYii2 yii2mod/yii2-rbac
【发布时间】:2018-12-28 19:56:54
【问题描述】:

我试图了解它是如何工作的 - 没办法 我只能看到以 /rbac/ .. 开头的路线,还有一些以 /gridview/ ... 和 /dynagrid/ ... 开头的路线 但没有与我的控制器操作相关的路线 我认为 yii2mod/yii2-rbac 在 Yii1 中像 RBAC 一样工作,我在控制器中定义并签入了权限。

当 - 像以前一样 - 我插入这样的东西:

INSERT INTO `auth_item` (`name`, `type`, `description`, `rule_name`, `data`) VALUES ('createCompany', 0, 'createCompany', NULL, 'N;');

并将其分配给用户 Admin,它在 Admin 的权限视图中显示为权限而不是路由 (rbac/permission/view/Admin)

自述文件对我没有帮助 - 那么我该如何使用 yii2mod/yii2-rbac 呢?

【问题讨论】:

  • 你是不是想了解yii2的rbac机制?还想知道单独的包yii2mod/yii2-rbac吗?
  • 视情况而定 - 会选择我能理解的那个

标签: yii2 rbac


【解决方案1】:

yii2mod/yii2-rbac 包它提供的是一个网络界面,但它不是 Yii2 中 RBAC 的原生实现的替代方案:

Yii2-RBAC 为高级访问控制和 包括以下功能:

  • 允许对角色、权限、规则进行 CRUD 操作
  • 允许为用户分配多个角色或权限
  • 允许创建控制台迁移
  • yii2mod/base 集成

这个包的基础是 RBAC Yii2,它可以查看其部分实现here(仅作为示例)。

auth_item 表创建一个原始的INSERT 对于理解RBAC 的工作原理没有多大意义。 auth_item 表保存按类型分隔的权限和/或角色的记录:1=Role, 2=permission。

在您的项目中安装和配置yii2mod/yii2-rbac,您可以输入不同的选项来创建角色、权限、路由并将它们分配给您的用户,因为他们可以:

http://localhost/path/to/index.php?r=rbac/
http://localhost/path/to/index.php?r=rbac/route
http://localhost/path/to/index.php?r=rbac/permission
http://localhost/path/to/index.php?r=rbac/role
http://localhost/path/to/index.php?r=rbac/assignment

或者如果您启用了漂亮的网址,您可以使用以下网址:

http://localhost/path/to/index.php/rbac
http://localhost/path/to/index.php/rbac/route
http://localhost/path/to/index.php/rbac/permission
http://localhost/path/to/index.php/rbac/role
http://localhost/path/to/index.php/rbac/assignment

如果您想更好地了解 YB2 RBAC 的工作原理,您可以从 here 查看它。

【讨论】:

    猜你喜欢
    • 2016-06-09
    • 2016-08-26
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多