PHPackages                             zc/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. zc/yii2-rbac

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

zc/yii2-rbac
============

User rbac module

1.0.x-dev(10y ago)015MITPHP

Since Nov 26Pushed 10y ago1 watchersCompare

[ Source](https://github.com/davidfang/yii2-rbac)[ Packagist](https://packagist.org/packages/zc/yii2-rbac)[ RSS](/packages/zc-yii2-rbac/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

RBAC Manager for Yii 2
======================

[](#rbac-manager-for-yii-2)

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

[](#installation)

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

Either run

```
php composer.phar require --prefer-dist zc/yii2-rbac "*"
php composer.phar require "yiisoft/yii2-jui": "~2.0@dev" //can't be installed via composer.json requiremtns because of DependencyResolver issue

```

or add

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

to the require section of your composer.json.

Usage
-----

[](#usage)

Once the extension is installed, simply modify your application configuration as follows:

```
return [
    //....
    'modules' => [
        'rbac' => [
            'class' => 'zc\rbac\Module',
            //Some controller property maybe need to change.
            'controllerMap' => [
                'assignment' => [
                    'class' => 'zc\rbac\controllers\AssignmentController',
                    'userClassName' => 'path\to\models\User',
                ]
            ]
        ],
    ],

  'components' => [
        ....
        'user' => [
                    'identityClass' => 'common\models\User',//'app\models\AdminUser',用户模型
                    'enableAutoLogin' => true,
                    'loginUrl' => ['user/login'],//登录地址
                ],
         'authManager' => [
            'class' => 'yii\rbac\DbManager',
            'defaultRoles' => ['guest', 'user'],
            'cache' => 'yii\caching\FileCache',
            //'itemTable' => 'AuthItem',
            //'itemChildTable' => 'AuthItemChild',
            //'assignmentTable' => 'AuthAssignment',
            //'ruleTable' => 'AuthRule',
        ],
    ]
    'as access' => [
        'class' => 'zc\rbac\components\AccessControl',
        'allowActions' => [
            '/',
            'home/*',
            'backend/reflushmenu',
            'home/captcha',
            'home/error',
            'user/logout',
            'user/login',
            //'some-controller/some-action',
            // The actions listed here will be allowed to everyone including guests.
            // So, 'admin/*' should not appear here in the production, of course.
            // But in the earlier stages of your development, you may probably want to
            // add a lot of actions here until you finally completed setting up rbac,
            // otherwise you may not even take a first step.
        ],
        'rules'        => [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
            [
                'actions' => ['logout'],
                'allow' => true,
                'roles' => ['@'],
            ],
            [
                'actions' => ['error'],
                'allow'   => true,
            ],
            [
                'actions' => ['login'],
                'allow'   => true,
                'roles'   => ['?'],
            ],
        ],
    ],
];
```

you need execute rbac init migration by the following command:

```
php yii migrate/up --migrationPath=@zc/rbac/migrations

```

You can then access Auth manager through the following URL:

```
http://localhost/path/to/index.php?r=rbac/
http://localhost/path/to/index.php?r=rbac/route
http://localhost/path/to/index.php?r=rbac/permission
http://localhost/path/to/index.php?r=rbac/role
http://localhost/path/to/index.php?r=rbac/assignment

```

For applying rules add to your controller following code:

```
use zc\rbac\components\AccessControl;

class ExampleController extends Controller
{

/**
 * 如果在配置文件里面配置了，这里就可以不用了
 * Returns a list of behaviors that this component should behave as.
 */
public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::className(),
            ],
            'verbs' => [
                ...
            ],
        ];
    }
  // Your actionss
}
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Unknown

Total

1

Last Release

3751d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b29cb353d503891d92c92f627effda01079dc22fc8520b833e63823483289fbe?d=identicon)[davidfang](/maintainers/davidfang)

---

Top Contributors

[![davidfang](https://avatars.githubusercontent.com/u/6745559?v=4)](https://github.com/davidfang "davidfang (12 commits)")[![dmitry-semenov](https://avatars.githubusercontent.com/u/17027799?v=4)](https://github.com/dmitry-semenov "dmitry-semenov (12 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (2 commits)")

---

Tags

yii2module

### Embed Badge

![Health badge](/badges/zc-yii2-rbac/health.svg)

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

###  Alternatives

[budyaga/yii2-users

Module for manage users and their rights with the support of registration through social services and assigned to each user more than one social service.

409.1k](/packages/budyaga-yii2-users)[vova07/yii2-rbac-module

The RBAC module for Yii framework.

191.2k2](/packages/vova07-yii2-rbac-module)[lowbase/yii2-user

Yii2 user module

131.5k2](/packages/lowbase-yii2-user)

PHPackages © 2026

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