PHPackages                             nullref/yii2-rbac - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. nullref/yii2-rbac

ActiveYii2-extension[Authentication &amp; Authorization](/categories/authentication)

nullref/yii2-rbac
=================

13091PHP

Since Mar 31Pushed 6y ago3 watchersCompare

[ Source](https://github.com/NullRefExcep/yii2-rbac)[ Packagist](https://packagist.org/packages/nullref/yii2-rbac)[ RSS](/packages/nullref-yii2-rbac/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2 RBAC (in development now)
==============================

[](#yii2-rbac-in-development-now)

[![Latest Stable Version](https://camo.githubusercontent.com/de90d245bbe4f83fb2cd3a2de12dfb1c82996f25f8fe951ae452bb28a2061296/68747470733a2f2f706f7365722e707567782e6f72672f6e756c6c7265662f796969322d726261632f762f737461626c65)](https://packagist.org/packages/nullref/yii2-rbac) [![Total Downloads](https://camo.githubusercontent.com/e25599d5d556976c72ba99d89cb1bc4335c69fe5fdd77ebfdcf99ea79a64aca3/68747470733a2f2f706f7365722e707567782e6f72672f6e756c6c7265662f796969322d726261632f646f776e6c6f616473)](https://packagist.org/packages/nullref/yii2-rbac) [![Latest Unstable Version](https://camo.githubusercontent.com/9f22ef1a955062bc571a2cea60da023965efe315d8f56ec100562d170490a266/68747470733a2f2f706f7365722e707567782e6f72672f6e756c6c7265662f796969322d726261632f762f756e737461626c65)](https://packagist.org/packages/nullref/yii2-rbac) [![License](https://camo.githubusercontent.com/a2d4d4cf002d12f5b78351f8413e0043fb914ef82f8304e6a559f60d2f6a7f7b/68747470733a2f2f706f7365722e707567782e6f72672f6e756c6c7265662f796969322d726261632f6c6963656e7365)](https://packagist.org/packages/nullref/yii2-rbac)

Advanced RBAC superstructure on yii2 RBAC, Dektrium extension

**Main functions:**

1. **Action access by roles and permissions**
2. **UI element access by roles and permissions**
3. **Model field access by scenarios,roles and permissions**

**Installation**

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist nullref/yii2-rbac "*"
```

or add

```
"nullref/yii2-rbac": "*"
```

to the require section of your `composer.json` file.

**Basic set up:**

At first you need to configure `authManager` component to use database. You need to use `\nullref\rbac\components\DBManager`.

In modules configuration on 'rbac' section you

- need to specify id (ex: user, admin, etc) of userComponent `\yii\web\User`with identity field and getId() method in it
- need to specify userProvider class which implements interface

```
nullref\rbac\interfaces\UserProviderInterface
```

with getUsers() method which has to return array of users with required fields \['id', 'username'\]

- may to override ruleManager class which implements interface

```
nullref\rbac\interfaces\RuleManagerInterface
```

with getList() method, there is RuleManager in module

```
nullref\rbac\components\RuleManager
```

**Your modules configuration:**In `Module.php` add array with aliases for module controllers

Ex:

```
  public $controllerAliases = [
        '@app/modules/myModule/controllers',
        '@app/modules/myModule/controllers/admin',
  ];
```

Each controller you want to be under RBAC has to be extended from:

```
\nullref\rbac\components\BaseController
```

or behavior() method has contain next item:

```
 'access' => [
                'class'      => \nullref\rbac\filters\AccessControl::class,
                'controller' => $this,
            ],
```

**Usage of UI element access:**

To use this functionality you have to:

- use widget in base layout

```

```

- specify $elementEditorRole in RBAC module by default 'elementEditor'
- assign this role to your user
- use html helper to build you 'a' and 'button'(for now) tags.

```
nullref\rbac\helpers\elementt\ElementHtml
```

and provide data-identifier option with unique value to $options array

```
