简体   繁体   English

用户角色数据结构

[英]User roles data structure

This is my STRUCTURE for User role permissions 这是我的用户角色权限结构

    permissions
    id
    name = The name of the __ACTION__ like, "UpdateNews" or something like that

roles
id
name = Guest/Admin/etc.

role_permissions //connect the roles with permissions
role_id 
permission_id

The idea is that I do something like this: 我的想法是做这样的事情:

$user->hasPermission('updateNews') !== false
// do stuff

Now, this requires me to give users all permissions, that is required, the thing is, Let's say I have a role called "administrator", and I would like to give him all permissions, in a quick way, instead of adding all rows, how can the easiest and best way do this? 现在,这需要我向用户授予所有权限,这就是,假设我有一个名为“管理员”的角色,并且我想快速地给他所有权限,而不是添加所有行,最简单,最好的方法是怎么做到的? And while we are on it, are my user role approach good? 而且,尽管我们坚持不懈,但我的用户角色方法很好吗?

hmm, for administrator you could have a class/method that can override this hasPermission method. 嗯,对于管理员,您可以拥有一个可以覆盖此hasPermission方法的类/方法。 And for this approach, instead of checking by your own code before every invocation, try to use some technique like aspect-oriented programming. 对于这种方法,请尝试使用诸如面向方面的编程之类的技术,而不是在每次调用前都检查自己的代码。

http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=5734277 http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=5734277

(note:article might be a little bit overkill) (注意:文章可能有点过大)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM