marqu3s / yii2-rbac-plus
Database role base access control manager for yii2
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 52
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: >=2.0.40
This package is auto-updated.
Last update: 2024-12-12 21:51:03 UTC
README
Database role base access control manager for yii2.
Features
- CRUD operations for roles, permissions and rules
- Allows to assign multiple roles to user
- Nice views to intergrate right away
Installation
The preferred way to install this extension is through composer.
php composer.phar require marqu3s/yii2-rbac-plus
Usage
1. Let's add into modules config in your main config file:
'components' => [
'authManager' => [
'class' => 'yii\rbac\DbManager',
],
],
'modules' => [
'rbac' => [
'class' => 'marqu3s\rbacplus\Module'
]
]
Next, update the database schema:
php yii migrate/up --migrationPath=@yii/rbac/migrations
Ok. That's done. Avaiable route now:
- /rbac/rule
- /rbac/permission
- /rbac/role
- /rbac/assignment
2. The module configuration avaible
'modules' => [
'rbac' => [
'class' => 'marqu3s\rbacplus\Module',
'userModelClassName' => null,
'userModelIdField' => 'id',
'userModelLoginField' => 'username',
'userModelLoginFieldLabel' => null,
'userModelExtraDataColumls' => null,
'beforeCreateController' => null,
'beforeAction' => null
]
],
- userModelClassName: The user model class.
If you not set or set null, RBAC Plus will be get fromYii::$app->getUser()->identityClass
- userModelIdField: The user model id field.
Default id field is 'id', you must set this config if primary key of user table in database is not 'id' - userModelLoginField The user model login field.
Default login field is 'username'. Maybe you use email field or something other for login. So you must change this config - userModelLoginFieldLabel The user model login field label.
If you set null the label will get from$userModelClass->attributeLabels()[$userModelLoginField]
- userModelExtraDataColumls The extra data columns you want to show in user assign views.
The default in assignment data gridview just display id and login column data. if you want to add created_at column you can add
'userModelExtraDataColumls' => [
[
'attributes' => 'created_at',
'format' => 'datetime',
]
],
- beforeCreateController The callable before create all controller of Rbac Plus module.
The default it is null. You need config this when you want to restrict access to Rbac Plus module.
Example:
'beforeCreateController' => function($route) {
/**
*@var string $route The route consisting of module, controller and action IDs.
*/
}
- beforeActionThe callable before action of all controller in Rbac Plus module.
The default it is null. You need config this when you want to restrict access to any action in some controller of Rbac Plus module.
Example:
'beforeAction' => function($action) {
/**
*@var yii\base\Action $action the action to be executed.
*/
}