MVC中的权限控制解决思路
MVC中的权限控制
想到两种方法:
1、建一张权限表,在Controller基类中判断用户是否有使用该控制器该方法的权限;
2、在每个方法前调用函数判断用户是否有权限访问。
大家一般是怎么做的呢?
另外,如何在CodeIgniter中管理权限?该框架没有提供这一功能,有个叫FreakAuth的插件,不太想用。自己写的话怎样实现呢?改写Controller基类?添加hook?还是在每个方法中判断?
谢谢
------解决方案--------------------
------解决方案--------------------
去研究下 thinkphp试试
www.thinkphp.cn
------解决方案--------------------
咱也没到这种境界 学习
------解决方案--------------------
没用过ci, 不过既然能够知道controller和action了,
那么只要你自己继承基类,写个认证方法,判断当前用户是否有权限访问controller和action
要采用此认证的controller就继承这个基类。
------解决方案--------------------
没有遇见过你分析的问题
我用过MVC的ruby-on-rails和分析过MVC模式的uchome
没有你说的给每一个用户分配方法权限问题
他们的处理只只给控制器分配方法,比如:这个控制器只能用哪些方法,至于哪些用户可以用,可设一前置函数
我一般是这样处理的
1、在控制器设定前置验证函数,可以标示应用于哪些方法,如果没有权限,则提示,不用执行方法
2、在方法中直接进行验证权限,比如有的方法需要验证的,可以验证session,cookie,全局全变,或全局方法
------解决方案--------------------
up
------解决方案--------------------
大多数MVC框架都可以实现这一功能。
如果是ZF的话,可以用Controller的helper实现。
如果自己写代码,可以用Template设计模式实现。

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

Introduction In today's rapidly evolving digital world, it is crucial to build robust, flexible and maintainable WEB applications. The PHPmvc architecture provides an ideal solution to achieve this goal. MVC (Model-View-Controller) is a widely used design pattern that separates various aspects of an application into independent components. The foundation of MVC architecture The core principle of MVC architecture is separation of concerns: Model: encapsulates the data and business logic of the application. View: Responsible for presenting data and handling user interaction. Controller: Coordinates the interaction between models and views, manages user requests and business logic. PHPMVC Architecture The phpMVC architecture follows the traditional MVC pattern, but also introduces language-specific features. The following is PHPMVC

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.
