search
HomeBackend DevelopmentPHP TutorialPHP-后台权限管理设计问题

有没有哪位大哥做过后台权限管理这个模块的?能否给我说下你的设计思路?有文档给我看看也行(我也在网上找了资料,才来提问的,不要让我自行百度好吗?心塞...)

我是这么想的,有三张表,管理员表管理组表规则表

<code>管理员表(members)
 m_id       m_name   m_passw   m_groupid
管理员ID     用户名    密码     管理所对应的管理组ID  

规则表(rules)
r_id     r_name      r_method         r_status
规则ID    规则名    控制器名/方法名      状态

管理组(group)
g_id     g_name     g_content
组ID      组名       组权限(包含这一组所有的规则ID)</code>

如上面代码里的,我觉得三张表就可以应付了,为什么我看到网上有6、7张表,之多,中间有关联表映射表什么的东西,我想知道,这么多表具体有什么作用呢?实际操作起来(操作数据库)还很复杂,如果是必须,具体作用是什么?求解答疑惑

回复内容:

有没有哪位大哥做过后台权限管理这个模块的?能否给我说下你的设计思路?有文档给我看看也行(我也在网上找了资料,才来提问的,不要让我自行百度好吗?心塞...)

我是这么想的,有三张表,管理员表管理组表规则表

<code>管理员表(members)
 m_id       m_name   m_passw   m_groupid
管理员ID     用户名    密码     管理所对应的管理组ID  

规则表(rules)
r_id     r_name      r_method         r_status
规则ID    规则名    控制器名/方法名      状态

管理组(group)
g_id     g_name     g_content
组ID      组名       组权限(包含这一组所有的规则ID)</code>

如上面代码里的,我觉得三张表就可以应付了,为什么我看到网上有6、7张表,之多,中间有关联表映射表什么的东西,我想知道,这么多表具体有什么作用呢?实际操作起来(操作数据库)还很复杂,如果是必须,具体作用是什么?求解答疑惑

你可以看一下PHPCMS的权限设计

常见的设计方式RBAC:
设计思路:通过对当前访问URI进行权限鉴定
数据结构:

<code>表1:权限表,用于存放所有的访问URI
表2:权限组表,存权限组拥有访问权限的URI的id
表2:权限组,权限组对应有哪些用户
</code>

大致就是这么个思路

在你的基础上补充一下,你后台应该有一张后台菜单目录表,表里面记录了具体菜单名称对应的控制器方法名信息,权限规则表里把存控制器信息字段可以改成存菜单ID,多个可以逗号隔开。

一张用户表(必须字段gourpid 记录该属于用户组id), 一张用户组表(必须字段node,用来记录菜单表id,用逗号隔开记录),一张后台菜单表(用来记录菜单的url,也用于后台菜单遍历出菜单)。 用户登陆时,查询该用户属于哪个用户组,取出用户组的node,然后用node查出菜单遍历出菜单,也可以做相应的权限

  1. 可以看一下 YII2 的权限设计,每个用户可以对应多个角色,不同角色可以设置不同的权限:http://www.yiichina.com/doc/guide/2.0/security-authorization

  2. 或者参考一下discuz的权限设置

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What is the best way to send an email using PHP?What is the best way to send an email using PHP?May 08, 2025 am 12:21 AM

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

Best Practices for Dependency Injection in PHPBest Practices for Dependency Injection in PHPMay 08, 2025 am 12:21 AM

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHP performance tuning tips and tricksPHP performance tuning tips and tricksMay 08, 2025 am 12:20 AM

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

PHP Email Security: Best Practices for Sending EmailsPHP Email Security: Best Practices for Sending EmailsMay 08, 2025 am 12:16 AM

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

How do you optimize PHP applications for performance?How do you optimize PHP applications for performance?May 08, 2025 am 12:08 AM

TooptimizePHPapplicationsforperformance,usecaching,databaseoptimization,opcodecaching,andserverconfiguration.1)ImplementcachingwithAPCutoreducedatafetchtimes.2)Optimizedatabasesbyindexing,balancingreadandwriteoperations.3)EnableOPcachetoavoidrecompil

What is dependency injection in PHP?What is dependency injection in PHP?May 07, 2025 pm 03:09 PM

DependencyinjectioninPHPisadesignpatternthatenhancesflexibility,testability,andmaintainabilitybyprovidingexternaldependenciestoclasses.Itallowsforloosecoupling,easiertestingthroughmocking,andmodulardesign,butrequirescarefulstructuringtoavoidover-inje

Best PHP Performance Optimization TechniquesBest PHP Performance Optimization TechniquesMay 07, 2025 pm 03:05 PM

PHP performance optimization can be achieved through the following steps: 1) use require_once or include_once on the top of the script to reduce the number of file loads; 2) use preprocessing statements and batch processing to reduce the number of database queries; 3) configure OPcache for opcode cache; 4) enable and configure PHP-FPM optimization process management; 5) use CDN to distribute static resources; 6) use Xdebug or Blackfire for code performance analysis; 7) select efficient data structures such as arrays; 8) write modular code for optimization execution.

PHP Performance Optimization: Using Opcode CachingPHP Performance Optimization: Using Opcode CachingMay 07, 2025 pm 02:49 PM

OpcodecachingsignificantlyimprovesPHPperformancebycachingcompiledcode,reducingserverloadandresponsetimes.1)ItstorescompiledPHPcodeinmemory,bypassingparsingandcompiling.2)UseOPcachebysettingparametersinphp.ini,likememoryconsumptionandscriptlimits.3)Ad

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.