ThinkPHP
模板和操作映射功能是ThinkPHP3.1.2版本支持的对模块和操作设置的映射机制,由于可以通过改变配置动态改变(实际真正改变,并非别名)URL访问地址,加强了应用的安全性,而且,映射机制具有URL不区分大小写访问的特性,对于应用的迁移也有很大的帮助。
因为,普通情况下,如果需要更改URL的模块或者操作访问的话,需要改动的文件较多,容易导致关联性出错。尤其是很多应用需要迁移到新版本的时候,由于模型和控制器改动较多,导致URL地址出现大的调整,通过模块和操作映射功能,就可以很轻松的解决此类问题。
1.模块映射
要定义模块映射,我们只需要在配置文件中定义:
'URL_MODULE_MAP'=>array( 'user' => 'Member', 'blog' => 'Info', )
URL_MODULE_MAP是一个数组,每个数组项表示:
'模块映射名'=>'实际模块名'
映射名称不区分大小写,所以设置后,URL访问从原来的:
http://serverName/index.php/Member/index http://serverName/index.php/Info/index
变成了:
http://serverName/index.php/user/index http://serverName/index.php/blog/index
并且原来的访问URL是失效的,这也是和定义路由方式改变URL的区别之一。没有定义映射的模块访问不变。
定义了模块映射后,可以通过MODULE_ALIAS常量读取当前模块的URL名称。
2.操作映射
不仅是模块名称可以映射,操作名称也支持映射,而且是针对模块来设置的,操作映射的定义方式为:
'URL_ACTION_MAP'=>array( 'Member' => array( 'register' => 'add', ), 'Info' => array( 'list' => 'index' ), )
URL_ACTION_MAP参数是一个二维数组,每个数组项表示:
'实际模块名'=>array( '操作映射名1'=>'实际操作名1' '操作映射名2'=>'实际操作名2' ...... )
操作映射名不区分大小写,如上定义后,URL访问从
http://serverName/index.php/Member/add http://serverName/index.php/Info/index
变成了(不考虑前面定义的模块映射):
http://serverName/index.php/Member/register http://serverName/index.php/Info/list
同样,原来的URL地址访问则失效。没有定义映射的操作访问地址不变。
定义了操作映射后,可以通过ACTION_ALIAS常量读取当前操作在URL地址中的操作名。
操作映射和模块映射可以同时定义,没有影响,例如:
'URL_MODULE_MAP'=>array( 'user' => 'Member', ), 'URL_ACTION_MAP'=>array( 'Member' => array( 'register888' => 'add', ), )
则,原来的注册地址
http://serverName/index.php/Member/add
变成了
http://serverName/index.php/user/register888
3.U函数自动支持
可能很多人会担心,在设置了模块和操作映射后,U函数就会出现需要随之改动的情况。其实不需要担心,因为U函数内部已经自动支持了模块和操作映射的情况。
例如,原来在模板文件中使用了
<a href="{:U('Member/add')}">用户注册</a>
无论如何定义Member模块和add操作的映射,U方法的写法始终保持不变,仍然会正确的指向映射后的URL地址。
总结:
模块和操作映射可以用于如下场合:
1、有经常变化URL需要的场合
2、对URL安全性较高的场合
3、需要移植的应用不希望改变URL地址的场合
需要注意的事项:
在使用了模块和操作映射后,对相关URL地址的路由定义可能需要调整。

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools

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.