Rea*_*ado 11 php mysql arrays permissions store
我正在为我们的公司开发一个应用程序,最终将有很多方法将用户限制在特定的部分/模块中.虽然应用程序仍然很小,但我想转向一种存储权限的新方法,随着应用程序的增长,这种方法仍然易于维护和查询.
目前在我们的MySQL数据库中,我们有一个名为"user"的表,它存储用户的ID,用户名和密码.在另一个名为"user_acl"的表中,如下所示:
user_acl_id
acl_root
acl_news_read
acl_news_write
acl_news_modify
acl_reports_read
acl_reports_write
acl_reports_modify
acl_users_read
acl_users_write
acl_users_modify
Run Code Online (Sandbox Code Playgroud)
我们每分钟只有3个模块,但随着时间的推移会创建更多模块,并且需要添加每个模块的权限.
而不是为每个权限创建一个列,有没有其他方式或存储此信息?
Ibr*_*mar 31
我会这样做的.
table name: permission
columns: id, permission_name
Run Code Online (Sandbox Code Playgroud)
然后我可以使用多对多关系表为用户分配多个权限
table name: user_permission
columns: permission_id, user_id
Run Code Online (Sandbox Code Playgroud)
这个设计允许我添加任意数量的权限,并将其分配给我想要的尽可能多的用户.
虽然上面的设计符合您的要求,但我有自己的方法在我的应用程序中实现ACL.我在这里发帖.
我的ACL实现方法如下:
为此,我提出了以下数据库设计.
role
I store the role name here
+----------+
| Field |
+----------+
| id |
| roleName |
+----------+
permission:
I store the permission name and key here
Permission name is for displaying to user.
Permission key is for determining the permission.
+----------------+
| Field |
+----------------+
| id |
| permissionName |
| permissionKey |
+----------------+
role_permission
I assign permission to role here
+---------------+
| Field |
+---------------+
| id |
| role_id |
| permission_id |
+---------------+
user_role
I assign role to the user here
+---------------+
| Field |
+---------------+
| id |
| user_id |
| role_id |
+---------------+
user_permission
I store the manual permission I may allow for the user here
+---------------+
| Field |
+---------------+
| id |
| user_id |
| permission_id |
+---------------+
Run Code Online (Sandbox Code Playgroud)
这使我可以更好地控制ACL.我可以让superadmins自己分配权限,等等.正如我所说,这只是为了给你这个想法.