memclutter / yii2-rbac-migration
Migration helper trait for Yii2
Installs: 337
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: *
This package is not auto-updated.
Last update: 2017-08-11 14:16:21 UTC
README
Migration helper trait for Yii2
Installation
PHP 5.4 or higher is required to use it.
Installation is recommended to be done via composer by running:
composer require memclutter/yii2-rbac-migration "*"
Alternatively you can add the following to the require
section in your composer.json
manually:
"memclutter/yii2-rbac-migration": "*"
Run composer update
afterwards.
Usage
Here are some examples:
class mXXXXXX_YYYYYY_rbac extends Migration { use \memclutter\rbac\MigrationTrait; public function up() { // create 'user' and 'admin' role, make 'user' child role of 'admin' $this->createRole('user', ['description' => 'Simple user']); $this->createRole('admin', ['description' => 'Administrator']); $this->addChildRole('admin', 'user'); // create permission 'updatePost' and make child of 'admin' role. $this->createPermission('updatePost', ['description' => 'Update blog post']); $this->addPermissionForRole('admin', 'updatePost'); // create permission 'updateOwnPost' and make child of 'user' role. $this->createPermission('updateOwnPost', ['description' => 'Update own post']); $this->addPermissionForRole('user', 'updateOwnPost'); } public function down() { // drop all permissions and roles $this->dropPermissionForRole('user', 'updateOwnPost'); $this->dropPermission('updateOwnPost'); $this->dropPermissionForRole('admin', 'updatePost'); $this->dropPermission('updatePost'); $this->dropChildRole('admin', 'user'); $this->dropRole('admin'); $this->dropRole('user'); } }