lawiet / yii2-rolemanager
RBAC with access menu
Installs: 94
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Type:yii2-extension
Requires
- kartik-v/yii2-builder: @dev
- kartik-v/yii2-icons: @dev
- kartik-v/yii2-widget-select2: @dev
- kartik-v/yii2-widgets: *
- yiisoft/yii2: ^2.0.8
- yiisoft/yii2-bootstrap: *
- yiisoft/yii2-jui: *
Requires (Dev)
Suggests
- yiisoft/yii2-bootstrap: Used when using layout 'left-menu', 'right-menu' or 'top-menu'
This package is auto-updated.
Last update: 2025-03-01 00:11:59 UTC
README
Component to use Role Manager with Yii2
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require lawiet/yii2-rolemanager "dev-master"
or add
"minimum-stability": "dev",
"prefer-stable": true,
require: {
...
"lawiet/yii2-rolemanager": "@dev"
...
}
to the require section of your composer.json
file.
Role configuration
In file web.php
<?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
<?php
....
use lawiet\rbac\web\Controller;
class xxxController extends Controller {
...
?>
And remove method behaviors or modify and add the method parent
<?php
....
class xxxController extends Controller {
....
public function behaviors()
{
return parent::behaviors();
}
...
?>
Generate principal menu dynamically in your layout add
<?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
php yii migrate --migrationPath=@lawiet/rbac/migrations --interactive=0