PHPackages                             casbin/codeigniter-permission - 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. casbin/codeigniter-permission

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

casbin/codeigniter-permission
=============================

Associate users with roles and permissions, use Casbin in CodeIgniter4 Web Framework.

v2.0.0(1y ago)443.0k9Apache-2.0PHPPHP ^8.1

Since Mar 9Pushed 1y ago12 watchersCompare

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

READMEChangelog (3)Dependencies (3)Versions (5)Used By (0)

 CodeIgniter Permission
========================

[](#----codeigniter-permission)

 **CodeIgniter Permission is an authorization library for the CodeIgniter4 framework.**

 [ ![Build Status](https://github.com/php-casbin/codeigniter-permission/actions/workflows/phpunit.yml/badge.svg) ](https://github.com/php-casbin/codeigniter-permission/actions/workflows/phpunit.yml) [ ![Coverage Status](https://camo.githubusercontent.com/f856a408f73145cc0c992de6f2e6809702cf8677356c279203474de563291c48/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7068702d63617362696e2f636f646569676e697465722d7065726d697373696f6e2f62616467652e737667) ](https://coveralls.io/github/php-casbin/codeigniter-permission) [ ![Latest Stable Version](https://camo.githubusercontent.com/f02eed150a6d0b2ff991d98c33a51a1662f16272d179b6da7a976a3627bcf16e/68747470733a2f2f706f7365722e707567782e6f72672f63617362696e2f636f646569676e697465722d7065726d697373696f6e2f762f737461626c65) ](https://packagist.org/packages/casbin/codeigniter-permission) [ ![Total Downloads](https://camo.githubusercontent.com/d2334178f1ee4a3125d72be1d22ac9ece0c0213f7f9b79bf70fec3cd2e3f139c/68747470733a2f2f706f7365722e707567782e6f72672f63617362696e2f636f646569676e697465722d7065726d697373696f6e2f646f776e6c6f616473) ](https://packagist.org/packages/casbin/codeigniter-permission) [ ![License](https://camo.githubusercontent.com/0c3d7978c42f8ae3d40fe81785c7b68210712c8c9b64d56d2a0372340b5f4465/68747470733a2f2f706f7365722e707567782e6f72672f63617362696e2f636f646569676e697465722d7065726d697373696f6e2f6c6963656e7365) ](https://packagist.org/packages/casbin/codeigniter-permission)

It's based on [Casbin](https://github.com/php-casbin/php-casbin), an authorization library that supports access control models like ACL, RBAC, ABAC.

All you need to learn to use `Casbin` first.

- [Installation](#installation)
- [Usage](#usage)
    - [Quick start](#quick-start)
    - [Using Enforcer Api](#using-enforcer-api)
    - [Multiple enforcers](#multiple-enforcers)
    - [Cache](#using-cache)
- [Thinks](#thinks)
- [License](#license)

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

[](#installation)

Require this package in the `composer.json` of your `CodeIgniter 4` project. This will download the package.

```
composer require casbin/codeigniter-permission

```

To migrate the migrations, run the migrate command:

```
php spark migrate -n "Casbin\CodeIgniter"

```

This will create a new table named `rules`

Usage
-----

[](#usage)

### Quick start

[](#quick-start)

Once installed you can do stuff like this:

```
$enforcer = \Config\Services::enforcer();

// adds permissions to a user
$enforcer->addPermissionForUser('eve', 'articles', 'read');
// adds a role for a user.
$enforcer->addRoleForUser('eve', 'writer');
// adds permissions to a rule
$enforcer->addPolicy('writer', 'articles','edit');
```

You can check if a user has a permission like this:

```
// to check if a user has permission
if ($enforcer->enforce("eve", "articles", "edit")) {
    // permit eve to edit articles
} else {
    // deny the request, show an error
}
```

### Using Enforcer Api

[](#using-enforcer-api)

It provides a very rich api to facilitate various operations on the Policy:

Gets all roles:

```
$enforcer->getAllRoles(); // ['writer', 'reader']
```

Gets all the authorization rules in the policy.:

```
$enforcer->getPolicy();
```

Gets the roles that a user has.

```
$enforcer->getRolesForUser('eve'); // ['writer']
```

Gets the users that has a role.

```
$enforcer->getUsersForRole('writer'); // ['eve']
```

Determines whether a user has a role.

```
$enforcer->hasRoleForUser('eve', 'writer'); // true or false
```

Adds a role for a user.

```
$enforcer->addRoleForUser('eve', 'writer');
```

Adds a permission for a user or role.

```
// to user
$enforcer->addPermissionForUser('eve', 'articles', 'read');
// to role
$enforcer->addPermissionForUser('writer', 'articles','edit');
```

Deletes a role for a user.

```
$enforcer->deleteRoleForUser('eve', 'writer');
```

Deletes all roles for a user.

```
$enforcer->deleteRolesForUser('eve');
```

Deletes a role.

```
$enforcer->deleteRole('writer');
```

Deletes a permission.

```
$enforcer->deletePermission('articles', 'read'); // returns false if the permission does not exist (aka not affected).
```

Deletes a permission for a user or role.

```
$enforcer->deletePermissionForUser('eve', 'articles', 'read');
```

Deletes permissions for a user or role.

```
// to user
$enforcer->deletePermissionsForUser('eve');
// to role
$enforcer->deletePermissionsForUser('writer');
```

Gets permissions for a user or role.

```
$enforcer->getPermissionsForUser('eve'); // return array
```

Determines whether a user has a permission.

```
$enforcer->hasPermissionForUser('eve', 'articles', 'read');  // true or false
```

See [Casbin API](https://casbin.org/docs/en/management-api) for more APIs.

### Multiple enforcers

[](#multiple-enforcers)

If you need multiple permission controls in your project, you can configure multiple enforcers.

In the `Config\Enforcer.php` file, it should be like this:

```
namespace Config;

use Casbin\CodeIgniter\Config\Enforcer as BaseConfig;
use Casbin\CodeIgniter\Adapters\DatabaseAdapter;

class Enforcer extends BaseConfig
{
    /*
     * Default Enforcer driver
     *
     * @var string
     */
    public $default = 'basic';

    public $basic = [
        /*
        * Casbin model setting.
        */
        'model' => [
            // Available Settings: "file", "text"
            'config_type' => 'file',

            'config_file_path' => __DIR__.'/rbac-model.conf',

            'config_text' => '',
        ],

        /*
        * Casbin adapter .
        */
        'adapter' => DatabaseAdapter::class,

        /*
        * Database setting.
        */
        'database' => [
            // Database connection for following tables.
            'connection' => '',

            // Rule table name.
            'rules_table' => 'rules',
        ],

        'log' => [
            // changes whether Casbin will log messages to the Logger.
            'enabled' => false,

            // Casbin Logger
            'logger' => \Casbin\CodeIgniter\Logger::class,
        ],

        'cache' => [
            // changes whether Casbin will cache the rules.
            'enabled' => false,

            // cache Key
            'key' => 'rules',

            // ttl int|null
            'ttl' => 24 * 60,
        ],
    ];

    public $second = [
        'model' => [
            // ...
        ],

        'adapter' => DatabaseAdapter::class,
        // ...
    ];
}
```

Then you can choose which enforcers to use.

```
$enforcer->guard('second')->enforce("eve", "articles", "edit");
```

### Using cache

[](#using-cache)

Authorization rules are cached to speed up performance. The default is off.

Sets your own cache configs in `Config\Enforcer.php`.

```
'cache' => [
    // changes whether Casbin will cache the rules.
    'enabled' => false,
    // cache Key
    'key' => 'rules',
    // ttl int|null
    'ttl' => 24 * 60,
]
```

Thinks
------

[](#thinks)

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

License
-------

[](#license)

This project is licensed under the [Apache 2.0 license](LICENSE).

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance39

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 86.7% 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 ~863 days

Total

3

Last Release

536d ago

Major Versions

v1.1.0 → v2.0.02024-11-29

PHP version history (2 changes)v1.0.0PHP &gt;=7.2

v2.0.0PHP ^8.1

### 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 (13 commits)")[![basakest](https://avatars.githubusercontent.com/u/47746206?v=4)](https://github.com/basakest "basakest (1 commits)")[![hsluoyz](https://avatars.githubusercontent.com/u/3787410?v=4)](https://github.com/hsluoyz "hsluoyz (1 commits)")

---

Tags

access-controlaclauthorizationcodeigniterpermissionsrbacrestfulcodeigniterauthorizationaclpermissionrbacaccess-controlabaccasbin

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/casbin-codeigniter-permission/health.svg)

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

###  Alternatives

[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/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)[hosseinhezami/laravel-permission-manager

Advanced permission manager for Laravel.

403.3k](/packages/hosseinhezami-laravel-permission-manager)

PHPackages © 2026

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