bariew / yii2-rbac-cms-module
从UI进行访问管理
1.0.5
2019-12-09 08:41 UTC
Requires
- bariew/phpquery: dev-master
- bariew/yii2-node-tree: 2.0.*
- yiisoft/yii2-jui: *
README
描述
管理对网站控制器动作的访问。将所有权限存储在数据库中。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一:
php composer.phar require --prefer-dist bariew/yii2-rbac-cms-module "*"
或者在您的 composer.json
文件的 require 部分添加:
"bariew/yii2-rbac-cms-module": "*"
to the require section of your composer.json
file.
使用方法
- 在主配置文件的 components 部分定义 authManager 组件,您还需要一些 i18n 设置(示例)
'components' => [
...
'authManager' => [
'class' => '\yii\rbac\DbManager'
],
'i18n' => [ // this example only if you don't have i18n defined in any other way.
'translations' => [
'*' => [
'class' => 'yii\i18n\PhpMessageSource',
],
],
],
],
- 在 modules 配置部分中包含 'rbac' 模块
'modules' => [
...
'rbac' => [
'class' => 'bariew\rbacModule\Module'
],
],
-
从模块迁移文件夹应用迁移。例如,您可以将这些迁移复制到您的应用程序迁移文件夹并运行常见的 yii 控制台迁移命令。
-
转到 rbac/auth-item/index URL 并创建一些角色和权限,使用带有鼠标右键的菜单树。
-
使用 AuthItem::checkAccess() 为 beforeAction 事件,使用 ViewAccess::afterRender() 为 afterRender 事件。您还可以以常规方式使用 Yii::$app->authManager。