简体   繁体   English

PHP中一个用户的各种角色

[英]Various roles for one user in PHP

I have an idea of doing a back office for my website.我有一个为我的网站做后台的想法。 The problem is that, when I introduce a user who has, for example, two roles, I want the user to choose the role to work with, but I can't figure out how to do that.问题是,当我介绍一个具有两个角色的用户时,我希望用户选择要使用的角色,但我不知道如何做到这一点。 I've tried so different things such as putting the two roles separate with commas in MySQL and separating them in PHP but it didn't work.我尝试了很多不同的事情,例如在 MySQL 中用逗号将两个角色分开并在 PHP 中将它们分开,但它没有用。

let say you have a user table, and a user can have multiple role.假设你有一个用户表,一个用户可以有多个角色。

you can create a master table for role ( let say roles )您可以为角色创建一个主表(比如角色)

角色表

you can have a field on user table say user_roles -> it can have values like 1,2,4你可以在用户表上有一个字段说 user_roles -> 它可以有像 1,2,4 这样的值

note:- there should not be gaps between the numbers / comma注意:- 数字/逗号之间不应有间隙

on the front-end you can take a mutiselect / tags UI element to input role for the user.在前端,您可以使用 mutiselect / tags UI 元素为用户输入角色。

to fetch the role of a user at server side - you can use explode() + in_array() to check the role if exists在服务器端获取用户的角色 - 您可以使用 expand() + in_array() 来检查角色是否存在

comma separated example 逗号分隔示例

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

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