Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter -- Best implementation for ACL [closed]

What's the best way to implement ACL in CodeIgniter?

  • DB based roles, groups, user persmissions?
  • Create a library?

Here is what we're working with:

Articles, Authors

There are two types of author:

  • Normal author (can only see his own articles).
  • Author that is also an admin (can see all articles and approves other author's articles).

Considering the functionality will expand (more features that will need permission restriction for types of authors), what is the best way to do ACL in CodeIgniter?

like image 420
Hopstream Avatar asked Apr 05 '11 17:04

Hopstream


1 Answers

You will need to separate controllers for each type of permission, and have a module that checks the session variable set when the user logs in with the type of permission allowed for that particular controller.

// module User_model:
function is_logged_in_admin()
{
    $is_logged_in = $this->session->userdata('is_logged_in');
    $user_status = $this->session->userdata('user_type');
    if(!isset($is_logged_in) || $is_logged_in != true || $user_status != 'admin')
    {
    $this->session->sess_destroy();  
    redirect('please_login/', 'refresh');           

    }       
}

Controller , load the module and check in the construct:

    function __construct()
{
    parent::__construct();
    $this->load->model('User_model'); 
        $this->User_model-> is_logged_in_admin();

}
like image 156
tylerpenney Avatar answered Nov 03 '22 08:11

tylerpenney