View on GitHub

Ezrbac

A simple yet easy to implement Role Based Access Control Library for popular PHP framework Codeigniter

Download this project as a .zip file Download this project as a tar.gz file

ezRbac

A simple yet easy to implement Role Based Access Control Library for popular PHP framework Codeigniter

Key Features

Current Stable Release

v1.3..2 Released!

How To Install

Installation of this library is simple 4 steps

  1. Put ezRbac in the third_party Directory of your application

  2. Run the SQL in schema directory or create three tables in your database manually.

  3. Set $config['enable_hooks'] = TRUE; at ./application/config/config.php

  4. Add a hook in ./application/config/hooks.php

$hook['post_controller_constructor'] = array(
    'class' => 'EzRbacHook',
    'function' => 'AccessCheck',
    'filename' => 'EzRbacHook.php',
    'filepath' => 'third_party/ezRbac'
);

Map custom actions to access map

Define a public function named access_map in your controller something like bellow:

 public function access_map(){
        return array(
            'index'=>'view',
            'update'=>'edit'
        );
    }

The index of the array is the actual action name, and the value mapped to the access privileges configured as $config['default_access_map'] = array("view", "create", "edit", "delete", "publish")

Default credential

If you have imported the provided data.sql then the default credential is

user:       admin@admin.com
password:   123456

ezRbac Specific URL

logout url : /index.php/welcome/index/rbac/logout

acl manage url : /index.php/welcome/index/rbac/gui

If you have enabled the routing(see How to eneable Routing) then you can access all url like /rbac/(logout|gui)

How to enable Routing

Its easy to enable with 2 steps

  1. Set $config['use_routing'] = true; at ./ezRbac/config/ez_rbac.php

  2. set $route['^(rbac)/(.+)$'] = $route['default_controller']."/index/$1/$2"; at /application/config/routes.php (where rbac can be replaced whatever you like by setting the $config['ezrbac_url'] = 'rbac';)

Customization

Most of the customization can be done through setting configuration values. you can customize configuration in two ways:

  1. (The Easy way) Modify the configuration to match with your choice at ./third_party/ezRbac/config/ez_rbac.php
  2. (The Advanced way) Make a copy of ./third_party/ezRbac/config/ez_rbac.php as ./application/config/ez_rbac.php or Create new file to override the default settings. These way whenever you do update the library, you do not need to worry about your configuration values.

You can override the view file also. just copy the view files into /application/views/ezrbac/ and modify as per your need. Currently only views in login directory is extensible.

Configuration Options

default : array(
          'id'                  => 'id',
          'email'               => 'email',
          'password'            => 'password',
          'salt'                => 'salt',
          'user_role_id'        => 'user_role_id',
          'last_login'          => 'last_login',
          'last_login_ip'       => 'last_login_ip',
          'reset_request_code'  => 'reset_request_code',
          'reset_request_time'  => 'reset_request_time',
          'reset_request_ip'    => 'reset_request_ip',
          'verification_status' => 'verification_status',
          'status'              => 'status'
      );  

The database field map for your existing system. Helpful to adapt your db without modifying the code!!

ezRbac Api reference

You can use this api from your controller to interact with this library. Api methods are accessible through ezrbac property of controller. For an example you can use $this->ezrbac->getCurrentUser() from your controller to get the user object for logged in user.

Available API

$userdata details

The $userdata array can contain the following fields

Dependencies

To use this library you need Codeigniter 2.1