Yii2 Role Manager
Component to use Role Manager with Yii2, (*1)
Installation
The preferred way to install this extension is through composer., (*2)
Either run, (*3)
php composer.phar require lawiet/yii2-rolemanager "dev-master"
or add, (*4)
"minimum-stability": "dev",
"prefer-stable": true,
require: {
...
"lawiet/yii2-rolemanager": "@dev"
...
}
to the require section of your composer.json
file., (*5)
Role configuration
In file web.php
, (*6)
<?php
....
'user' => [
'identityClass' => 'lawiet\rbac\models\User',
'enableAutoLogin' => true,
//'authTimeout' => 30,
],
....
'modules' => [
'rbac' => [
'class'=>'lawiet\rbac\Module',
'excludes'=>[
//'modules' => ['test'], //List id Modules to RBAC exclude
//'controllers' => ['test.default'], //List id controllers to RBAC exclude module.controller
//'actions' => ['test.default.index'], //List id action to RBAC exclude module.controller.action
],
'menu'=>[
'icon'=>true, // boolean show icon true or false. Default: true
],
],
],
...
?>
In each file controllers/xxxController.php
change yii\web\Controller for lawiet\rbac\web\Controller, (*7)
<?php
....
use lawiet\rbac\web\Controller;
class xxxController extends Controller {
...
?>
And remove method behaviors or modify and add the method parent, (*8)
<?php
....
class xxxController extends Controller {
....
public function behaviors()
{
return parent::behaviors();
}
...
?>
Generate principal menu dynamically in your layout add, (*9)
<?php
....
use lawiet\rbac\web\Access;
....
NavBar::begin([
'brandLabel' => Yii::t('app', 'My Company'),
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
echo Nav::widget(Access::getPrincipalMenu());
NavBar::end();
...
?>
Run command, (*10)
php yii migrate --migrationPath=@lawiet/rbac/migrations --interactive=0