So i’m still using CodeIgniter on my latest project and while I would prefer to use Zend Framework, CodeIgniter is getting the job done. There are some required things however that CodeIgniter does not do well out of the box. Things like Authentication, ACL and Unit Testing.

The first of these issues, i needed to tackle was the ACL (Access Control List). Turns out Zend has a really good ACL library, which i’ve used before. Their documentation is also pretty decent.

Since i wanted to gently introduce my team to Zend framework I jumped at the opportunity to integrate the Zend ACL with CodeIgniter.

Here’s How.

  1. Download the latest zend framework package
  2. Create a Zend folder in CodeIgniter’s /application/libraries folder.
  3. Copy only the zend libraries you need to this folder. For now its just Acl, Acl.php and Exception.php
  4. Create the file CI_acl.php in your libraries folder and copy the code below into it.
  5. Add ‘CI_acl’ to the array $autoload[‘libraries’] in /system/application/config/autoload.php

//figure out the path to libraries. (your path may be different)
$libpath = rtrim(BASEPATH,'system/')
$libpath = $libpath.'/application/libraries';

// Set the include path.
// A more permanent solution would be to add this to your php ini file
set_include_path(get_include_path() . PATH_SEPARATOR . $libpath);
require_once 'Zend/Acl.php';
class CI_acl extends Zend_acl
     private $CI;
     function __construct()
      //create resources
      $this->add(new Zend_Acl_Resource('checklists'));
      $this->add(new Zend_Acl_Resource('issues'));
      $this->add(new Zend_Acl_Resource('projects'));

      //Create roles
      $this->addRole(new Zend_Acl_Role('contractor'));
      //Set up access rights
      $this->allow('contractor', 'projects');