开发者

CodeIgniter -- Best implementation for ACL [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 9 years ago.

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

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?


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();

}


I am in the process of writing an ACL based authorization system which checks permission on a URL level. It is supposed to be transparent and Authentication system agnostic. It is implemented as a post controller constructor hook.

Sadly its not finished. but you can check it out on github and fork it if you feel like finishing it. atm it only works with ACLs coded in a config file, but it allows for an external group/role source (i just havent written one yet).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜