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

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

antonyz89/yii2-rbac
===================

RBAC for Yii2 Framework

0.2.4(5y ago)011BSD-3-ClausePHPPHP &gt;=7.2

Since Aug 8Pushed 5y ago1 watchersCompare

[ Source](https://github.com/AntonyZ89/yii2-rbac)[ Packagist](https://packagist.org/packages/antonyz89/yii2-rbac)[ RSS](/packages/antonyz89-yii2-rbac/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (6)Dependencies (7)Versions (8)Used By (0)

yii2-rbac
=========

[](#yii2-rbac)

[ ![Donate with PayPal](https://camo.githubusercontent.com/648ad6f048733f167bf65e11a4fd759eef14da88db61ad078bbd5ddea5d57133/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e6174655f4c472e676966)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YATHVT293SXDL&source=url)Installation
------------

[](#installation)

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

Either run

```
$ composer require antonyz89/yii2-rbac dev-master

```

or add

```
"antonyz89/yii2-rbac": "dev-master"

```

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

Usage
-----

[](#usage)

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

```

Add bootstrap and module in to main.php

```
return [
    'bootstrap' => ['rbac'],
    'modules' => [
        'rbac' => ['class' => 'antonyz89\rbac\Module'],
    ],
]
```

---

Applying Rules
==============

[](#applying-rules)

1 - Add AccessControl to your Controller's Behaviour

```
use antonyz89\rbac\components\AccessControl;

/**
 * ExampleController implements the CRUD actions for Example model.
 */
class ExampleController extends Controller
{
    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        return [
            'access' => [
                'class' => AccessControl::class, /* add */
                /* optional fields */
                'rules' => [
                    [
                        'actions' => [
                            'create',
                            'update',
                            'view',
                            'index',
                        ],
                        'allow' => true,
                        'roles' => ['@'],
                    ],
                ],
            ],
            'verbs' => [
                'class' => VerbFilter::class,
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }
}
```

2 - Create a rbac\_profile\_id to your identity class

`php yii migrate/create add_rbac_profile_id_to_user_table`

```
