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

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

问题描述

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

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

  • 基于数据库的角色、组、用户权限?
  • 创建图书馆?

这是我们正在使用的:

文章、作者

有两种类型的作者:

  • 普通作者(只能看到自己的文章).
  • 同时也是管理员的作者(可以查看所有文章并批准其他作者的文章).

考虑到功能会扩展(更多功能需要对作者类型进行权限限制),在 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 ,加载模块并检查构造:

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天全站免登陆