juliardi / yii2-simple-rbac
Simple RBAC module for Yii 2 framework
Installs: 38
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 2
Type:yii2-extension
Requires
- php: >=5.4.0
- dmstr/yii2-helpers: *
- kartik-v/yii2-widget-select2: @dev
- yiisoft/yii2: >=2.0.5
- yiisoft/yii2-bootstrap: *
- yiisoft/yii2-swiftmailer: *
Requires (Dev)
This package is auto-updated.
Last update: 2022-09-26 05:04:46 UTC
README
Simple RBAC module for Yii 2 Framework
Caution : This package is still in development stage. Please do not use it for now.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist juliardi/yii2-simple-rbac "*"
or add
"juliardi/yii2-simple-rbac": "*"
to the require section of your composer.json
file and then run
php composer.phar update
Setup
Once the extension is installed, you must first set it up by :
-
Register yii2-simple-rbac as a module in
config\web.php
. Add this code beforereturn $config;
statement :$config['bootstrap'][] = 'simplerbac'; $config['modules']['simplerbac'] = [ 'class' => 'juliardi\simplerbac\Module', 'db' => 'db', //you can change this in case you are using different database for access control ];
-
Run migrations
php yii migrate/up --migrationPath=@juliardi/simplerbac/migrations
or in case you are using different database (we assume here as
db2
):php yii migrate/up --migrationPath=@juliardi/simplerbac/migrations --db=db2
-
Create 'user' table with a foreign key to table 'rbac_role'. You can see an example of yii2 migrations in
examples\migrations
directory. -
Generate the model and CRUD of 'user' table using Gii
-
Implements
juliardi\simplerbac\base\UserRbacInterface
in your User model. You can see an example of yii2 model inexamples\models
directory. -
You can now access it by visiting :
http://yourproject.dev/index.php?r=simplerbac
Usage
Once the extension is configured, simply use it by :
- Extends
juliardi/simplerbac/base/Controller
in your controller - That's all. You can set your access rules for your action by accessing :
http://yourproject.dev/index.php?r=simplerbac