PHPackages                             casbin/yii-adapter - 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. [Database &amp; ORM](/categories/database)
4. /
5. casbin/yii-adapter

AbandonedArchivedLibrary[Database &amp; ORM](/categories/database)

casbin/yii-adapter
==================

Use Casbin in Yii2 PHP Framework, Casbin is a powerful and efficient open-source access control library.

v1.0.0(6y ago)73.8k↓40%Apache-2.0PHP

Since Nov 16Pushed 5y ago2 watchersCompare

[ Source](https://github.com/php-casbin/yii-casbin)[ Packagist](https://packagist.org/packages/casbin/yii-adapter)[ RSS](/packages/casbin-yii-adapter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (5)Used By (0)

Yii-Casbin
==========

[](#yii-casbin)

[![Build Status](https://camo.githubusercontent.com/bb61ba5f53e9768da3645634ecebfd397504e1f0302d1e241bf9e360d9df7583/68747470733a2f2f7472617669732d63692e6f72672f7068702d63617362696e2f7969692d63617362696e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/php-casbin/yii-casbin)[![Coverage Status](https://camo.githubusercontent.com/0a58406bd86dd0fdcd28833b65884a1e6c2ec938861d03266d1b3150f1eb9071/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7068702d63617362696e2f7969692d63617362696e2f62616467652e737667)](https://coveralls.io/github/php-casbin/yii-casbin)[![Latest Stable Version](https://camo.githubusercontent.com/9688909c4eb246aeb1cdb0d608a7eff916609b39b46b4a211699c30d0ac27c91/68747470733a2f2f706f7365722e707567782e6f72672f63617362696e2f7969692d616461707465722f762f737461626c65)](https://packagist.org/packages/casbin/yii-adapter)[![Total Downloads](https://camo.githubusercontent.com/b71ff7217713c72c9f710c532c6752790b19f8d6e24a68b5791e01d457df5298/68747470733a2f2f706f7365722e707567782e6f72672f63617362696e2f7969692d616461707465722f646f776e6c6f616473)](https://packagist.org/packages/casbin/yii-adapter)[![License](https://camo.githubusercontent.com/ed0aa1850b4df44069beade9e67cf0e2b041fe1be9d10b3944c46bd6b3cf7414/68747470733a2f2f706f7365722e707567782e6f72672f63617362696e2f7969692d616461707465722f6c6963656e7365)](https://packagist.org/packages/casbin/yii-adapter)

> ## It is worth mentioning that we now recommend [Yii-Permission](https://github.com/php-casbin/yii-permission).
>
> [](#it-is-worth-mentioning-that-we-now-recommend-yii-permission)

Use [Casbin](https://github.com/php-casbin/php-casbin) in Yii 2.0 PHP Framework.

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

[](#installation)

### Getting Composer package

[](#getting-composer-package)

Require this package in the `composer.json` of your Yii 2.0 project. This will download the package.

```
composer require casbin/yii-adapter

```

### Configuring application

[](#configuring-application)

To use this extension, you have to configure the `Casbin` class in your application configuration:

```
return [
    //....
    'components' => [
        'casbin' => [
            'class' => '\CasbinAdapter\Yii\Casbin',

            /*
             * Yii-casbin model setting.
             */
            'model' => [
                // Available Settings: "file", "text"
                'config_type' => 'file',
                'config_file_path' => '/path/to/casbin-model.conf',
                'config_text' => '',
            ],

            // Yii-casbin adapter .
            'adapter' => '\CasbinAdapter\Yii\Adapter',

            /*
             * Yii-casbin database setting.
             */
            'database' => [
                // Database connection for following tables.
                'connection' => '',
                // CasbinRule tables and model.
                'casbin_rules_table' => '{{%casbin_rule}}',
            ],
        ],
    ]
];
```

Usage
-----

[](#usage)

This provides the basic access to Casbin via the `casbin` application component:

```
$casbin = \Yii::$app->casbin;

$sub = 'alice'; // the user that wants to access a resource.
$obj = 'data1'; // the resource that is going to be accessed.
$act = 'read'; // the operation that the user performs on the resource.

if (true === $casbin->enforce($sub, $obj, $act)) {
    // permit alice to read data1
} else {
    // deny the request, show an error
}
```

Define your own model.conf
--------------------------

[](#define-your-own-modelconf)

[Supported models](https://github.com/php-casbin/php-casbin#supported-models).

Learning Casbin
---------------

[](#learning-casbin)

You can find the full documentation of Casbin [on the website](https://casbin.org/).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity64

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

Every ~96 days

Total

4

Last Release

2447d ago

Major Versions

v0.2.0 → v1.0.02019-09-03

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

access-controlaclcasbinpermissionrbacyiidatabaseaclpermissionrbacyiiabaccasbincasbin-adapter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/casbin-yii-adapter/health.svg)

```
[![Health](https://phpackages.com/badges/casbin-yii-adapter/health.svg)](https://phpackages.com/packages/casbin-yii-adapter)
```

###  Alternatives

[casbin/yii-permission

Use Casbin in Yii2 PHP Framework, Casbin is a powerful and efficient open-source access control library.

468.0k](/packages/casbin-yii-permission)[casbin/casbin

a powerful and efficient open-source access control library for php projects.

1.3k1.4M54](/packages/casbin-casbin)[casbin/laravel-authz

An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.

324339.9k4](/packages/casbin-laravel-authz)[casbin/dbal-adapter

Database Abstraction Layer adapter for php-casbin.

1494.7k1](/packages/casbin-dbal-adapter)[casbin/think-authz

An authorization library that supports access control models like ACL, RBAC, ABAC for ThinkPHP.

27918.5k6](/packages/casbin-think-authz)[casbin/webman-permission

webman casbin permission plugin

523.4k2](/packages/casbin-webman-permission)

PHPackages © 2026

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