CodeIgniter - ACL的最佳实现 [英] CodeIgniter -- Best implementation for ACL

查看:138
本文介绍了CodeIgniter - ACL的最佳实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CodeIgniter中实现ACL的最佳方法是什么?

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


  • 基于数据库的角色,组,用户的观点?

  • 创建库?

以下是我们正在使用的产品:

Here is what we're working with:

文章,作者

有两种类型的作者:


  • 正常作者(只能看到自己的文章)。

  • 作者也是管理员(可以查看所有文章并批准其他作者的文章)。

考虑到功能会扩展(更多功能需要对作者类型的权限限制),在CodeIgniter中做ACL的最好方法是什么?

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

}

这篇关于CodeIgniter - ACL的最佳实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆