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

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

rockyfc/yii2-smart-rbac
=======================

Smart Rbac Manager for Yii2

08PHP

Since Sep 5Pushed 7y agoCompare

[ Source](https://github.com/rockyfc/yii2-smart-rbac)[ Packagist](https://packagist.org/packages/rockyfc/yii2-smart-rbac)[ RSS](/packages/rockyfc-yii2-smart-rbac/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Smart Rbac Manager for Yii2
===========================

[](#smart-rbac-manager-for-yii2)

本应用建立在Yii2的数据结构基础之上，使用之前请先安装yii2框架的rbac推荐的数据表。

网上提供的rbac功能界面理解起来有一定的难度，所以在项目中开发中重写了一套 RBAC。并把它分享出来。

其中包括四个模块：

- Action管理
- 角色管理
- 菜单管理
- 用户授权管理

在开发过程中，为了使用户能方便快速的的进行二次开发，基本代码层次和架构均同yii2框架的Module 书写方法，代码主体代码用gii生成。并且未对view层做过多修饰，必要时可自行调整。

安装方法
----

[](#安装方法)

推荐使用 [composer](http://getcomposer.org/download/) 安装

或者运行以下命令

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

```

或者将以下代码写进你的`composer.json` 文件中执行

```
"rockyfc/yii2-smart-rbac": "*"

```

使用方法
----

[](#使用方法)

将以下代码添加到你的配置文件中

```
//权限管理组件
'components' => [

    ...其他组件

    "authManager" => [
        // yii\rbac\DbManager的增强版
        "class" => 'smart\rbac\components\DbManager',
        "defaultRoles" => ["guest"],

        //菜单表名称
        "menuTable" => 'menu',

        //可以绑定角色的用户表名称
        "userTable" => 'user',
    ],

    ...其他组件

]
```

```
"modules" => [
    'rbac' => [
        'class' => 'smart\rbac\Module',

        //有些Module你并不想添加权限判断，则把它过滤掉
        'skipOn' => ['debug','gii'],
    ],
]
```

请将菜单表导入数据库（表名称可自定义）

```
CREATE TABLE `menu` (
  `menu_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '菜单ID',
  `parent_id` int(11) DEFAULT NULL COMMENT '上级菜单',
  `menu_name` varchar(50) NOT NULL COMMENT '菜单名称',
  `url` varchar(300) NOT NULL DEFAULT '' COMMENT '链接地址',
  `icon` varchar(100) DEFAULT NULL COMMENT '菜单icon图',
  `create_at` int(11) DEFAULT NULL COMMENT '创建时间',
  `update_at` int(11) NOT NULL COMMENT '更新时间',
  `action_id` varchar(100) DEFAULT NULL COMMENT '当前菜单关联的actionId',
  `order_by` int(11) NOT NULL DEFAULT '0' COMMENT '排序值，越大越靠前',
  `status` int(1) NOT NULL DEFAULT '2' COMMENT '是否可用1：不可用 2：可用',
  PRIMARY KEY (`menu_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='菜单管理表';
```

我们将 `@vendor\yiisoft\yii2\rbac\migrations\schema-mysql.sql` 文件导入数据库，或者通过可视化管理工具、手动等方式创建改文件中的数据表。

访问方法
----

[](#访问方法)

- 访问ction列表
- 访问Menu列表
- 访问用户列表
- 访问角色列表

@title标签的使用
-----------

[](#title标签的使用)

当你访问action列表的时候，如果"描述"列直接显示Action不够直观的话，可以在编写controller的时候给class和function的注释加上@title标签，重新"刷新"action列表就可以看到中文了。

```
/**
 *
 * @title 这里填写Controller标题
 */
class UserController extends Controller{

    /**
     * @title 这是action标题
     */
    public function actionIndex()
    {
       ...
    }
}
```

你也可以给Module class添加`@title`，方法同上。

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 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.

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[namshi/jose

JSON Object Signing and Encryption library for PHP.

1.8k99.6M101](/packages/namshi-jose)[league/oauth1-client

OAuth 1.0 Client Library

99698.8M106](/packages/league-oauth1-client)[bezhansalleh/filament-shield

Filament support for `spatie/laravel-permission`.

2.8k2.9M88](/packages/bezhansalleh-filament-shield)[gesdinet/jwt-refresh-token-bundle

Implements a refresh token system over Json Web Tokens in Symfony

70516.4M35](/packages/gesdinet-jwt-refresh-token-bundle)[league/oauth2-google

Google OAuth 2.0 Client Provider for The PHP League OAuth2-Client

41721.2M118](/packages/league-oauth2-google)[illuminate/auth

The Illuminate Auth package.

9327.3M1.0k](/packages/illuminate-auth)

PHPackages © 2026

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