PHPackages                             dmstr/yii2-active-record-permissions - 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. dmstr/yii2-active-record-permissions

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

dmstr/yii2-active-record-permissions
====================================

\_\_\_\_\_

1.2.5(9mo ago)144.0k↓11.5%2[1 issues](https://github.com/dmstr/yii2-active-record-permissions/issues)4BSD-3-ClausePHPPHP ^7.3 || ^8.0

Since May 11Pushed 9mo ago7 watchersCompare

[ Source](https://github.com/dmstr/yii2-active-record-permissions)[ Packagist](https://packagist.org/packages/dmstr/yii2-active-record-permissions)[ Docs](https://www.dmstr.io/)[ RSS](/packages/dmstr-yii2-active-record-permissions/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (3)Versions (16)Used By (4)

Yii 2 Active Record Access Permissions
======================================

[](#yii-2-active-record-access-permissions)

The package has been extracted from

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

[](#installation)

Setup
-----

[](#setup)

General usage
-------------

[](#general-usage)

### Configuration options

[](#configuration-options)

In application config:

```
    'params' => [
        'ActiveRecordAccessTrait' => [
            'enableRecursiveRoles' => true
        ],
    ],

```

> Note: Static property usage `enableRecursiveRoles` is deprecated.

### Example

[](#example)

Traits
------

[](#traits)

### [dmstr\\activeRecordPermissions\\ActiveRecordAccessTrait](https://github.com/dmstr/yii2-db/blob/master/db/traits/ActiveRecordAccessTrait.php)

[](#dmstractiverecordpermissionsactiverecordaccesstrait)

**Option 1:**

How to equip your active record model with access control

- Use update migration in `db/migrations/m160609_090908_add_access_columns`

    - set all `$tableNames` to be updated and run migration

This migrations adds the available access check columns to your database table(s)

```
'access_owner',
'access_read',
'access_update',
'access_delete',
'access_domain',

```

- Add `use \dmstr\activeRecordPermissions\ActiveRecordAccessTrait;` to your active record model
- *(update your cruds)*

### RBAC permissions

[](#rbac-permissions)

Permissions for selections

- `access.availableDomains:any`

Permissions to set default values

- `access.defaults.accessDomain:global`
- `access.defaults.updateDelete:`

Add rule for default value in `Model::rules()`, if you want to set it automatically

```
[
    [
        'access_update',
        'access_delete',
    ],
    'default',
    'value' => self::getDefaultAccessUpdateDelete()
],

```

**Option 2:**

Simply override this method in our AR model and set the access fields you have/want to the field names you have/want!

*Default:*

```
public static function accessColumnAttributes()
{
   return [
       'owner'  => 'access_owner',
       'read'   => 'access_read',
       'update' => 'access_update',
       'delete' => 'access_delete',
       'domain' => 'access_domain',
   ];
}

```

*Customize:*

```
public static function accessColumnAttributes()
{
    return [
        'owner'  => 'user_id',			// the column name with owner permissions
        'read'   => 'read_permission',	// the column name with read permissions
        'update' => false, 				// will do no access checks for update
        'delete' => false, 				// will do no access checks for delete
        'domain' => 'language',			// the column name with the access domain permission
    ];
}

```

**㊙️ Congrats, you are now ready to manage specific access checks on your active records!**

💡 Access options:

- All access option `*`
- specific rbac roles and permissions assignable

    - single or multi
        - `*`
        - `Role1,Role2,Permission1,...`
- limit access to specific domain / language

    - `de` or `en`
- `Owner` gets all access over other given permissions

    - every active record can have exact one owner right which stands above `access_read`, `access_update`, `access_delete`

Planned updates:
----------------

[](#planned-updates)

- ActiveRecordAccessTrait
    - in cruds use select2 multi for inputs (domain, read, update, delete)
        - Setter: authItemArrayToString()
        - Getter: authItemStringToArray()

---

Built by [dmstr](http://diemeisterei.de)

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community20

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

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

Every ~212 days

Recently: every ~281 days

Total

10

Last Release

284d ago

PHP version history (2 changes)1.0.0PHP ^7.3

1.2.1PHP ^7.3 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3b4ab2b6685ec71887908ec8cff261a16cd5bb24c69bb8ab52840e220f175f9d?d=identicon)[schmunk](/maintainers/schmunk)

---

Top Contributors

[![eluhr](https://avatars.githubusercontent.com/u/13000805?v=4)](https://github.com/eluhr "eluhr (21 commits)")[![schmunk42](https://avatars.githubusercontent.com/u/649031?v=4)](https://github.com/schmunk42 "schmunk42 (14 commits)")[![handcode](https://avatars.githubusercontent.com/u/825574?v=4)](https://github.com/handcode "handcode (4 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dmstr-yii2-active-record-permissions/health.svg)

```
[![Health](https://phpackages.com/badges/dmstr-yii2-active-record-permissions/health.svg)](https://phpackages.com/packages/dmstr-yii2-active-record-permissions)
```

###  Alternatives

[rmrevin/yii2-ulogin

Extension for yii2 ulogin integration

1811.9k](/packages/rmrevin-yii2-ulogin)[kakadu-dev/yii2-jwt-auth

Extension provide JWT auth for Yii2

105.8k](/packages/kakadu-dev-yii2-jwt-auth)

PHPackages © 2026

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