uses the Authority permission class that comes with ThinkPHP! ThinkPHP version is 3.1.3
What I want to achieve is to assign permissions based on the module name. Of course, this can be extended to the operation name.
If I have these module files:
Then the contents of the think_auth_rule table should be almost like this:
For example, my login user’s uid=7.
The think_auth_group_access table has uid=9, group=6;
The think_auth_group table has id=6, title=" Universe administrator", rules="4,5,8";
Then, I just need to add:
class CommAction extends Action{ public function __construct(){ parent::__construct(); $this->assign('waitSecond',2); $this->checkRight(); } private function checkRight(){ import('ORG.Util.Authority'); $auth=new Authority(); $r = $auth->getAuth(MODULE_NAME,session('S_USER_ID')); if(!$r){ $this->error('没有权限!'); } } }
to the module file CommAction.class.php, and then let other The module file inherits this file, for example, ActivityAction.class.php:
<?php class activityAction extends CommAction{ //操作方法 } ?>
In this way, when I access the modules with IDs 4, 5, and 8 in think_auth_rules, I can access it normally;
If you access the module with ID 10, 11, 12, 13, it will jump to the page that fails and prompts that there is no permission~
Now the problem I encounter when using this permission class is: think_auth_rule table I need to add the content manually. This part is developed by attributes. It would be great if it could be automatically generated.
Recommended tutorial: "TP5"
The above is the detailed content of Module permission assignment in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

The article discusses ThinkPHP's built-in testing framework, highlighting its key features like unit and integration testing, and how it enhances application reliability through early bug detection and improved code quality.

Article discusses using ThinkPHP for real-time stock market data feeds, focusing on setup, data accuracy, optimization, and security measures.

The article discusses key considerations for using ThinkPHP in serverless architectures, focusing on performance optimization, stateless design, and security. It highlights benefits like cost efficiency and scalability, but also addresses challenges

The article discusses implementing service discovery and load balancing in ThinkPHP microservices, focusing on setup, best practices, integration methods, and recommended tools.[159 characters]

ThinkPHP's IoC container offers advanced features like lazy loading, contextual binding, and method injection for efficient dependency management in PHP apps.Character count: 159

The article discusses using ThinkPHP to build real-time collaboration tools, focusing on setup, WebSocket integration, and security best practices.

ThinkPHP benefits SaaS apps with its lightweight design, MVC architecture, and extensibility. It enhances scalability, speeds development, and improves security through various features.

The article outlines building a distributed task queue system using ThinkPHP and RabbitMQ, focusing on installation, configuration, task management, and scalability. Key issues include ensuring high availability, avoiding common pitfalls like imprope


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

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.