PHPackages                             davidxu/yii2-srbac - 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. davidxu/yii2-srbac

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

davidxu/yii2-srbac
==================

Simple RBAC Manager with authManager is DbManager

v2.1.7(2y ago)012MITPHPPHP &gt;=8.0

Since Nov 10Pushed 2y agoCompare

[ Source](https://github.com/davidxuuts/yii2-srbac)[ Packagist](https://packagist.org/packages/davidxu/yii2-srbac)[ RSS](/packages/davidxu-yii2-srbac/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (20)Used By (0)

Yii2 SRbac
==========

[](#yii2-srbac)

Simple RBAC Manager fo Yii 2.0. Minify of [yii2-admin](https://github.com/mdmsoft/yii2-admin) extension with awesome features

[![Latest Stable Version](https://camo.githubusercontent.com/a444ef1987b2087d8614b21b07989a078278617ca605dd67a38390aa09b354ed/68747470733a2f2f706f7365722e707567782e6f72672f646176696478752f796969322d73726261632f762f737461626c65)](https://packagist.org/packages/davidxu/yii2-srbac) [![Total Downloads](https://camo.githubusercontent.com/54a502b0270c48f2aee8d7371b5b52202e622b76df1233850a77ad1ebaa5488e/68747470733a2f2f706f7365722e707567782e6f72672f646176696478752f796969322d73726261632f646f776e6c6f616473)](https://packagist.org/packages/davidxu/yii2-srbac) [![Latest Unstable Version](https://camo.githubusercontent.com/65adcb3eef34bac109eaf34fce431a19acc9d5e51546928faef98a592a8000e6/68747470733a2f2f706f7365722e707567782e6f72672f646176696478752f796969322d73726261632f762f756e737461626c65)](https://packagist.org/packages/davidxu/yii2-srbac) [![License](https://camo.githubusercontent.com/43b5f63db8f9a3c441e8d6e5a9b47259d63d1aa6ab9c6d1431a6b5ce816bef26/68747470733a2f2f706f7365722e707567782e6f72672f646176696478752f796969322d73726261632f6c6963656e7365)](https://packagist.org/packages/davidxu/yii2-srbac)

Attention
---------

[](#attention)

Before you install and use this extension, then make sure that your application has been using the login authentication to the database. especially for yii basic template. Because without it, this extension will produce error and useless.

Installation
------------

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist davidxu/yii2-srbac "^2.0"

```

or add

```
"davidxu/yii2-srbac": "^2.0"

```

or add this for install last change

```
"davidxu/yii2-srbac": "^2.0"

```

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

Configuration
-------------

[](#configuration)

Once the extension is installed, simply use it in your code by :

in config

```
'as access' => [
     'class' => '\davidxu\srbac\components\AccessFilter',
	 'allowActions' => [
		// add wildcard allowed action here!
		'site/*',
		'debug/*',
		'srbac/*', // only in dev mode
	],
],
...,
'modules' => [
	'srbac' => [
		'class' => '\davidxu\srbac\SrbacModule',
	],
	...
],
'components' => [
	'authManager' => [
		'class' => 'yii\rbac\DbManager', // only support DbManager
	],
],
```

Because this extension use 'yii\\rbac\\DbManager'as authManager, so You should migrate rbac sql first:

`yii migrate --migrationPath=@yii/rbac/migrations`

If You use Yii 2.0.6 version or newer, so then migrate custom table for this extension

`yii migrate --migrationPath=@davidxu/srbac/migrations`

But if You install Yii 2.0.5 version or older, so then migrate custom table for this extension

`yii migrate --migrationPath=@davidxu/srbac/migrations/old`

Usage
-----

[](#usage)

This RBAC manager have three main page, they are:

### Route

[](#route)

To get all action route from application. In here, You can on / off permission so not shown in menu role, rename alias/type of action route, so easy readable by end user. You can then access `Route` through the following URL:

```
http://localhost/path/to/index.php?r=srbac/route

```

### Role

[](#role)

To define level access of user, what he superadmin?, staff?, cashier? etc. In this menu, You can assign permission / action route (actions in application, they are create, update, delete, etc) to role. You can then access `Role` through the following URL:

```
http://localhost/path/to/index.php?r=srbac/role

```

Below screenshoot of route assignment to role [![Screenshoot Role](screenshoot.png "Screenshoot Role")](screenshoot.png)

### User

[](#user)

For standard user management, create/update/delete user, and assign role to user. You can then access `User` through the following URL:

```
http://localhost/path/to/index.php?r=srbac/user

```

We recommendate you for activate pretty URL.

Implementation on Widgets
-------------------------

[](#implementation-on-widgets)

### Example dynamic button

[](#example-dynamic-button)

It is used for checking if route right to access

```
if ((Srbac::checkRoute($this->context->id.'/create'))){
    echo Html::a('Create Note', ['create'], ['class' => 'btn btn-success']);
}

// in other case maybe You want ensure same of route so You can add parameter strict true
if ((Srbac::checkRoute($this->context->id.'/create',true))){
```

### Example dynamic menu

[](#example-dynamic-menu)

It is is used for filtering right access menu

```
use davidxu\srbac\components\Srbac;
$menuItems = [
    ['label' => 'Home', 'url' => ['/site/index']],
    ['label' => 'About', 'url' => ['/site/about']],
    ['label' => 'Contact', 'url' => ['/site/contact']],
];

if (\Yii::$app->user->isGuest){
    $menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
}
else{
    $menuItems[] = ['label' => 'App', 'items' => [
        ['label' => 'Category', 'url' => ['/category/index']],
        ['label' => 'Product', 'url' => ['/product/index']],
        ['label' => 'Cart', 'url' => ['/cart/index']],
    ]];
    $menuItems[] = [
        'label' => 'Logout (' . \Yii::$app->user->identity->username . ')',
        'url' => ['/site/logout'],
        'linkOptions' => ['data-method' => 'post']
    ];
}

$menuItems = Srbac::filterMenu($menuItems);
// in other case maybe You want ensure same of route so You can add parameter strict true
// $menuItems = Srbac::filterMenu($menuItems,true);

echo Nav::widget([
    'options' => ['class' => 'navbar-nav navbar-right'],
    'items' => $menuItems,
]);
```

### Example dynamic action column template

[](#example-dynamic-action-column-template)

It is used for filtering template of Gridview Action Column

```
use davidxu\srbac\components\Srbac;
echo GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ...,
        [
          'class' => 'yii\grid\ActionColumn',
          'template' => Srbac::filterActionColumn([
              'update','delete','download'
          ],$this->context->route),
          ...
        ]
    ]
]);
```

How to Contribute
-----------------

[](#how-to-contribute)

This tools is an OpenSource project so your contribution is very welcome.

In order to get started:

- Install this in your local (read installation section)
- Clone this repository.
- Check [README.md](README.md).
- Send [pull requests](https://github.com/davidxu/yii2-srbac/pulls).

Aside from contributing via pull requests you may [submit issues](https://github.com/davidxu/yii2-srbac/issues).

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 55.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~171 days

Recently: every ~65 days

Total

19

Last Release

760d ago

Major Versions

v1.1.5 → v2.0.02022-12-07

### Community

Maintainers

![](https://www.gravatar.com/avatar/59e94d6d1e147e3ed702e4f3dcbeb3eca9a9b228ad58dc014530212e0a3f3ba5?d=identicon)[davidxuuts](/maintainers/davidxuuts)

---

Top Contributors

[![hscstudio](https://avatars.githubusercontent.com/u/2976897?v=4)](https://github.com/hscstudio "hscstudio (25 commits)")[![davidxuuts](https://avatars.githubusercontent.com/u/1892196?v=4)](https://github.com/davidxuuts "davidxuuts (11 commits)")[![chabibnr](https://avatars.githubusercontent.com/u/4100006?v=4)](https://github.com/chabibnr "chabibnr (3 commits)")[![chiliman-oOo](https://avatars.githubusercontent.com/u/7079517?v=4)](https://github.com/chiliman-oOo "chiliman-oOo (2 commits)")[![luckynvic](https://avatars.githubusercontent.com/u/4830453?v=4)](https://github.com/luckynvic "luckynvic (2 commits)")[![m-alfan](https://avatars.githubusercontent.com/u/17586936?v=4)](https://github.com/m-alfan "m-alfan (1 commits)")[![virbo](https://avatars.githubusercontent.com/u/2990842?v=4)](https://github.com/virbo "virbo (1 commits)")

---

Tags

yii2extension

### Embed Badge

![Health badge](/badges/davidxu-yii2-srbac/health.svg)

```
[![Health](https://phpackages.com/badges/davidxu-yii2-srbac/health.svg)](https://phpackages.com/packages/davidxu-yii2-srbac)
```

###  Alternatives

[kakadu-dev/yii2-jwt-auth

Extension provide JWT auth for Yii2

105.8k](/packages/kakadu-dev-yii2-jwt-auth)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
