rmrevin / yii2-rbac-command
为 Yii2 更新 RBAC 规则的扩展
1.6.1
2017-03-08 13:42 UTC
Requires
- php: >=5.4.0
- yiisoft/yii2: 2.0.*
README
本扩展为 Yii framework 2.0 应用程序提供更新 RBAC 规则、角色和权限的命令行工具。
安装
composer require "rmrevin/yii2-rbac-command:~1.6"
配置
创建新的控制台命令,继承 \rmrevin\yii\rbac\Command
(示例)
<?php namespace app\commands; class RbacCommand extends \rmrevin\yii\rbac\Command { protected function rules() { // ... } protected function roles() { // ... } protected function permissions() { // ... } protected function inheritanceRoles() { // ... } protected function inheritancePermissions() { // ... } }
在控制台应用程序配置中(例如: /protected/config/console.php
)
<? return [ // ... 'controllerMap' => [ // ... 'rbac' => [ 'class' => 'app\commands\RbacCommand', 'batchSize' => 1000, 'forceAssign' => ['user'], // force assign user role for all users 'assignmentsMap' => [ 'frontend.old' => 'frontend.new', // after next update all `frontend.old` will be replaced by `frontend.new` ], 'useTransaction' => true, 'useCache' => true, ], ], // ... ];
用法
在命令行中执行命令
yii rbac/update