Skip to content

Commit

Permalink
优化配置
Browse files Browse the repository at this point in the history
  • Loading branch information
windhoney committed Apr 18, 2019
1 parent 01e3738 commit 245131e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',//选填,分组子表(已默认,可根据自己表名修改)
],
]
```
Expand All @@ -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/*',//可将路由配置到“普通员工”(默认角色)下
]
],
```
Expand Down
12 changes: 6 additions & 6 deletions components/DbManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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();
Expand All @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions models/AuthGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace wind\rest\models;

use wind\rest\components\DbManager;
use wind\rest\components\Helper;
use Yii;

Expand Down Expand Up @@ -31,7 +30,7 @@ public function __construct($id, array $config = [])
*/
public static function tableName()
{
return DbManager::$groupTable;
return Yii::$app->authManager->groupTable;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions models/AuthGroupsChild.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace wind\rest\models;

use wind\rest\components\DbManager;
use Yii;

/**
* Class AuthGroups
Expand All @@ -19,7 +19,7 @@ class AuthGroupsChild extends \yii\db\ActiveRecord
*/
public static function tableName()
{
return DbManager::$groupChildTable;
return Yii::$app->authManager->groupChildTable;
}

/**
Expand Down

0 comments on commit 245131e

Please sign in to comment.