PHPackages                             yiichina/yii2-rbac-module - 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. [Framework](/categories/framework)
4. /
5. yiichina/yii2-rbac-module

ActiveExtension[Framework](/categories/framework)

yiichina/yii2-rbac-module
=========================

Yii 2 RBAC Module

v1.0(7y ago)13331BSD-3-ClausePHP

Since Nov 25Pushed 7y ago2 watchersCompare

[ Source](https://github.com/yiichina/yii2-rbac-module)[ Packagist](https://packagist.org/packages/yiichina/yii2-rbac-module)[ Docs](https://www.yiichina.com/)[ RSS](/packages/yiichina-yii2-rbac-module/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Yii 2 RBAC Module
=================

[](#yii-2-rbac-module)

[![Latest Stable Version](https://camo.githubusercontent.com/82f2b1f77a2103856444fa588afb6ad83c1c4c76fd06a12aa674ee584dcf80df/68747470733a2f2f706f7365722e707567782e6f72672f7969696368696e612f796969322d726261632d6d6f64756c652f762f737461626c652e706e67)](https://packagist.org/packages/yiichina/yii2-rbac-module)[![Total Downloads](https://camo.githubusercontent.com/d95b8a0674f779e067a98fec4f65e444b996ffc787ea6a23170026b8a7f39513/68747470733a2f2f706f7365722e707567782e6f72672f7969696368696e612f796969322d726261632d6d6f64756c652f646f776e6c6f6164732e706e67)](https://packagist.org/packages/yiichina/yii2-rbac-module)[![Yii2](https://camo.githubusercontent.com/d6b0929173e28cc627430d2519ca1853466a70f37395877eaf4820cb3e1e1909/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f506f77657265645f62792d5969695f4672616d65776f726b2d677265656e2e7376673f7374796c653d666c6174)](http://www.yiiframework.com/)

安装
--

[](#安装)

安装这个扩展的首选方法是通过 [composer](http://getcomposer.org/download/)。

可以运行

```
composer require --prefer-dist yiichina/yii2-rbac-module "*"

```

也可以添加

```
"yiichina/yii2-rbac-module": "*"

```

到你的 `composer.json` 文件的包含部分。

安装方法
----

[](#安装方法)

### 配置模块

[](#配置模块)

```
'modules' => [
    'rbac' => [
        'class' => 'yiichina\modules\rbac\Module',
    ],
],

```

### 配置 RBAC

[](#配置-rbac)

```
'authManager' => [
    'class' => 'yii\rbac\DbManager',
    'defaultRoles' => ['user'],
],

```

### 初始化数据库

[](#初始化数据库)

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

```

也可以找到 `@yii/rbac/migrations` 目录下的数据库脚本去执行。

使用方法
----

[](#使用方法)

```
/index.php?r=rbac/assignment
/index.php?r=rbac/permission
/index.php?r=rbac/role
/index.php?r=rbac/rule

```

如果配置了 URL 美化，您可以使用如下 URL：

```
/rbac/assignment
/rbac/permission
/rbac/role
/rbac/rule

```

在需要权限判断的时候，使用如下方式：

```
if (Yii::$app->user->can('admin')) {
    // 可以执行的语句
}

```

使用控制器行为：

```
public function behaviors()
{
    return [
        'access' => [
            'class' => AccessControl::className(),
            'only' => ['delete'],
            'rules' => [
                'actions' => ['delete'],
                'allow' => true,
                'roles' => ['admin'], // 在这里指定可以操作此动作的角色
                'verbs' => ['POST'],
            ],
        ],
    ];
}

```

延伸阅读
----

[](#延伸阅读)

如果需要针对动作的权限管理，请参考：

同时包含 `DbManager` 和 `PhpManager` 的权限管理：

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

2727d ago

### Community

Maintainers

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

---

Top Contributors

[![cuileon](https://avatars.githubusercontent.com/u/313312?v=4)](https://github.com/cuileon "cuileon (13 commits)")

---

Tags

frameworkrbacyii2module

### Embed Badge

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

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

###  Alternatives

[skeeks/cms

SkeekS CMS — control panel and tools based on php framework Yii2

13825.6k47](/packages/skeeks-cms)[tecnocen/yii2-formgenerator

Yii 2 Library to configure form generator

145.7k](/packages/tecnocen-yii2-formgenerator)

PHPackages © 2026

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