diff --git a/README.md b/README.md index b8cf249..91dfc08 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,9 @@ composer require windhoney/yii2-rest-rbac 'components' => [ 'authManager' => [ 'class' => 'wind\rest\components\DbManager', //配置文件 + 'defaultRoles' => ['普通员工'] //选填,默认角色(默认角色下->公共权限(登陆,oauth2,首页等公共页面)) + 'groupTable' => 'auth_groups',//选填,分组表(已默认,可根据自己表名修改) + 'groupChildTable' => 'auth_groups_child',//选填,分组子表(已默认,可根据自己表名修改) ], ] ``` @@ -59,8 +62,8 @@ composer require windhoney/yii2-rest-rbac 'class' => 'wind\rest\components\AccessControl', 'allowActions' => [ 'site/*',//允许访问的节点,可自行添加 - 'rbac/menu/user-menu', - 'oauth2/*', + 'rbac/menu/user-menu',//可将路由配置到“普通员工”(默认角色)下 + 'oauth2/*',//可将路由配置到“普通员工”(默认角色)下 ] ], ``` diff --git a/components/DbManager.php b/components/DbManager.php index 89d3a99..cc1e828 100644 --- a/components/DbManager.php +++ b/components/DbManager.php @@ -55,11 +55,11 @@ class DbManager extends \yii\rbac\DbManager /** * @var string the name of the table storing groups. Defaults to "auth_groups". */ - public static $groupTable = 'auth_groups'; + public $groupTable = 'auth_groups'; /** * @var string the name of the table storing groups. Defaults to "auth_groups_child". */ - public static $groupChildTable = 'auth_groups_child'; + public $groupChildTable = 'auth_groups_child'; /** * @var Connection|array|string the DB connection object or the application component ID of the DB connection. * After the DbManager object is created, if you want to change this property, you should only assign it @@ -224,7 +224,7 @@ public function getGroups($group_name = null) { $query = (new Query) ->select(['group_id', 'group_name']) - ->from([self::$groupTable]) + ->from([$this->groupTable]) ->andFilterWhere(['group_name' => $group_name]) ->andWhere(['group_status' => 0]); $result = $query->all($this->db); @@ -243,7 +243,7 @@ public function getGroupChild($user_id) { $query = (new Query) ->select(['group_id']) - ->from([self::$groupChildTable]) + ->from([$this->groupChildTable]) ->andWhere(['user_id' => $user_id]); $result = $query->all($this->db); @@ -260,7 +260,7 @@ public function getGroupChild($user_id) public function assignGroup($group_id, $user_id) { $this->db->createCommand() - ->insert(self::$groupChildTable, [ + ->insert($this->groupChildTable, [ 'group_id' => $group_id, 'user_id' => $user_id ])->execute(); @@ -278,7 +278,7 @@ public function assignGroup($group_id, $user_id) public function revokeGroup($group_id, $user_id) { $this->db->createCommand() - ->delete(self::$groupChildTable, [ + ->delete($this->groupChildTable, [ 'group_id' => $group_id, 'user_id' => $user_id ])->execute(); diff --git a/models/AuthGroups.php b/models/AuthGroups.php index ef9fe79..06b273f 100644 --- a/models/AuthGroups.php +++ b/models/AuthGroups.php @@ -2,7 +2,6 @@ namespace wind\rest\models; -use wind\rest\components\DbManager; use wind\rest\components\Helper; use Yii; @@ -31,7 +30,7 @@ public function __construct($id, array $config = []) */ public static function tableName() { - return DbManager::$groupTable; + return Yii::$app->authManager->groupTable; } /** diff --git a/models/AuthGroupsChild.php b/models/AuthGroupsChild.php index 02f78fd..7dfe774 100644 --- a/models/AuthGroupsChild.php +++ b/models/AuthGroupsChild.php @@ -2,7 +2,7 @@ namespace wind\rest\models; -use wind\rest\components\DbManager; +use Yii; /** * Class AuthGroups @@ -19,7 +19,7 @@ class AuthGroupsChild extends \yii\db\ActiveRecord */ public static function tableName() { - return DbManager::$groupChildTable; + return Yii::$app->authManager->groupChildTable; } /**