Skip to content

Commit 245131e

Browse files
committed
优化配置
1 parent 01e3738 commit 245131e

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ composer require windhoney/yii2-rest-rbac
5050
'components' => [
5151
'authManager' => [
5252
'class' => 'wind\rest\components\DbManager', //配置文件
53+
'defaultRoles' => ['普通员工'] //选填,默认角色(默认角色下->公共权限(登陆,oauth2,首页等公共页面))
54+
'groupTable' => 'auth_groups',//选填,分组表(已默认,可根据自己表名修改)
55+
'groupChildTable' => 'auth_groups_child',//选填,分组子表(已默认,可根据自己表名修改)
5356
],
5457
]
5558
```
@@ -59,8 +62,8 @@ composer require windhoney/yii2-rest-rbac
5962
'class' => 'wind\rest\components\AccessControl',
6063
'allowActions' => [
6164
'site/*',//允许访问的节点,可自行添加
62-
'rbac/menu/user-menu',
63-
'oauth2/*',
65+
'rbac/menu/user-menu',//可将路由配置到“普通员工”(默认角色)下
66+
'oauth2/*',//可将路由配置到“普通员工”(默认角色)下
6467
]
6568
],
6669
```

components/DbManager.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ class DbManager extends \yii\rbac\DbManager
5555
/**
5656
* @var string the name of the table storing groups. Defaults to "auth_groups".
5757
*/
58-
public static $groupTable = 'auth_groups';
58+
public $groupTable = 'auth_groups';
5959
/**
6060
* @var string the name of the table storing groups. Defaults to "auth_groups_child".
6161
*/
62-
public static $groupChildTable = 'auth_groups_child';
62+
public $groupChildTable = 'auth_groups_child';
6363
/**
6464
* @var Connection|array|string the DB connection object or the application component ID of the DB connection.
6565
* 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)
224224
{
225225
$query = (new Query)
226226
->select(['group_id', 'group_name'])
227-
->from([self::$groupTable])
227+
->from([$this->groupTable])
228228
->andFilterWhere(['group_name' => $group_name])
229229
->andWhere(['group_status' => 0]);
230230
$result = $query->all($this->db);
@@ -243,7 +243,7 @@ public function getGroupChild($user_id)
243243
{
244244
$query = (new Query)
245245
->select(['group_id'])
246-
->from([self::$groupChildTable])
246+
->from([$this->groupChildTable])
247247
->andWhere(['user_id' => $user_id]);
248248
$result = $query->all($this->db);
249249

@@ -260,7 +260,7 @@ public function getGroupChild($user_id)
260260
public function assignGroup($group_id, $user_id)
261261
{
262262
$this->db->createCommand()
263-
->insert(self::$groupChildTable, [
263+
->insert($this->groupChildTable, [
264264
'group_id' => $group_id,
265265
'user_id' => $user_id
266266
])->execute();
@@ -278,7 +278,7 @@ public function assignGroup($group_id, $user_id)
278278
public function revokeGroup($group_id, $user_id)
279279
{
280280
$this->db->createCommand()
281-
->delete(self::$groupChildTable, [
281+
->delete($this->groupChildTable, [
282282
'group_id' => $group_id,
283283
'user_id' => $user_id
284284
])->execute();

models/AuthGroups.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace wind\rest\models;
44

5-
use wind\rest\components\DbManager;
65
use wind\rest\components\Helper;
76
use Yii;
87

@@ -31,7 +30,7 @@ public function __construct($id, array $config = [])
3130
*/
3231
public static function tableName()
3332
{
34-
return DbManager::$groupTable;
33+
return Yii::$app->authManager->groupTable;
3534
}
3635

3736
/**

models/AuthGroupsChild.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace wind\rest\models;
44

5-
use wind\rest\components\DbManager;
5+
use Yii;
66

77
/**
88
* Class AuthGroups
@@ -19,7 +19,7 @@ class AuthGroupsChild extends \yii\db\ActiveRecord
1919
*/
2020
public static function tableName()
2121
{
22-
return DbManager::$groupChildTable;
22+
return Yii::$app->authManager->groupChildTable;
2323
}
2424

2525
/**

0 commit comments

Comments
 (0)