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

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

davidxu/yii2-admin
==================

RBAC Auth manager for Yii2 based on mdm/yii2-admin

5.0.2(1y ago)015BSD-3-ClausePHP

Since May 27Pushed 1y agoCompare

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

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

DB-based RBAC Manager for Yii 2 Based on mdm/yii2-rbac
======================================================

[](#db-based-rbac-manager-for-yii-2-based-on-mdmyii2-rbac)

GUI manager for RBAC (Role Base Access Control) Yii2. Easy to manage authorization of user 😄.

[![Latest Stable Version](https://camo.githubusercontent.com/93df3875f59d566cc87aa6bf42fc4844550e8f99e523ac2233efe2fea18d74f1/68747470733a2f2f706f7365722e707567782e6f72672f646176696478752f796969322d61646d696e2f762f737461626c65)](https://packagist.org/packages/davidxu/yii2-admin)[![License](https://camo.githubusercontent.com/7203e5cf4151345739859a4b196588c21b824168817606ef029d90943820969f/68747470733a2f2f706f7365722e707567782e6f72672f646176696478752f796969322d61646d696e2f6c6963656e7365)](https://packagist.org/packages/davidxu/yii2-admin)

Documentation
-------------

[](#documentation)

- [Authorization Guide](http://www.yiiframework.com/doc-2.0/guide-security-authorization.html). Important, read this first before you continue.

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)

### Install With Composer

[](#install-with-composer)

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

Either run

```
php composer.phar require davidxu/yii2-admin "~5.0"

```

Or, you may add

```
"davidxu/yii2-admin": "~5.0"

```

to the requirement section of your `composer.json` file and execute `php composer.phar update`.

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

[](#configuration)

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

in config

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

Because this extension uses '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/admin/migrations`

Usage
-----

[](#usage)

This RBAC manager has four main pages, they are:

### Route

[](#route)

To get all action routes from application. In here, You can on / off permission so not shown in a 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=admin/route

```

Below screenshot of get all routes or add a route [![Screenshot Route](screenshot/screenshot-route.png "Screenshot Route")](screenshot/screenshot-route.png)

### Role

[](#role)

To define levels of access of user, what he super admin?, 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=admin/role

```

Below screenshot of route assignment to a role [![Screenshot Role](screenshot/screenshot-role.png "Screenshot Role")](screenshot/screenshot-role.png)

### User

[](#user)

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

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

```

Below screenshot of user management [![Screenshot User](screenshot/screenshot-user.png "Screenshot User")](screenshot/screenshot-user.png)

### Menu

[](#menu)

For backend management purpose, we can use sidebar menu. You can then access `Menu` through the following URL:

```
http://localhost/path/to/index.php?r=admin/menu

```

Below screenshot of menu management [![Screenshot Menu](screenshot/screenshot-menu.png "Screenshot Menu")](screenshot/screenshot-menu.png)

We recommend you to activate pretty URL.

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

[](#implementation-on-widgets)

### Example dynamic menu

[](#example-dynamic-menu)

It is used for filtering the right access menu

```
use davidxu\admin\components\MenuHelper;
use davidxu\adminlte4\widgets\Menu;
use Yii;
?>
