douxi3432 2013-10-29 07:28
浏览 54

在codeigniter中管理组权限

I know that this question has been as asked many times but as I am learning to write a better code. So need some suggestions.

Suppose, I have a controller and method as shown below:

:Account
login();
home();
manage_user();
logout();

:Company
add();
view();
edit();
delete();

:Service
add();
delete();

:Page
default();
about_us();
contact_us();

There are three types of user groups (eg. system admin, company user and general user) for which i need to specify permission to access these methods/pages.

I have a database structure as

group(id, name);
user(id, parent_id, group_id, company_id, username, password, email);
permission(id, group_id, uri, allowed);

uri field may contain values like, "company/add", "service/add", "company/view" ... etc.

I have an autoloaded library class as User having a method check_permission(), this method has been called on MY_Controller constructor.

So my question, is mapping controller/function to database field to permit access is a good practice? or do you have any other options which is more efficient than this?

  • 写回答

1条回答 默认 最新

  • dpiw16824 2013-10-29 08:31
    关注

    As per my opinion, it is always good to save the group permissions of each user in DB & have a permission mapping table. So that in future you can upgrade or downgrade the user's permission without touching the code (From admin panel)

    Also you need not make DB query in constructor of MY_Controller (in case if you are). When a user logs in, you can save his permission/group value in Session and just keep using that for further reference. This will save your query :)

    评论

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭