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

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


![WLAN expansion module has stopped [fix]](https://img.php.cn/upload/article/000/465/014/170832352052603.gif?x-oss-process=image/resize,m_fill,h_207,w_330)
If there is a problem with the WLAN expansion module on your Windows computer, it may cause you to be disconnected from the Internet. This situation is often frustrating, but fortunately, this article provides some simple suggestions that can help you solve this problem and get your wireless connection working properly again. Fix WLAN Extensibility Module Has Stopped If the WLAN Extensibility Module has stopped working on your Windows computer, follow these suggestions to fix it: Run the Network and Internet Troubleshooter to disable and re-enable wireless network connections Restart the WLAN Autoconfiguration Service Modify Power Options Modify Advanced Power Settings Reinstall Network Adapter Driver Run Some Network Commands Now, let’s look at it in detail

This article details methods to resolve event ID10000, which indicates that the Wireless LAN expansion module cannot start. This error may appear in the event log of Windows 11/10 PC. The WLAN extensibility module is a component of Windows that allows independent hardware vendors (IHVs) and independent software vendors (ISVs) to provide users with customized wireless network features and functionality. It extends the capabilities of native Windows network components by adding Windows default functionality. The WLAN extensibility module is started as part of initialization when the operating system loads network components. If the Wireless LAN Expansion Module encounters a problem and cannot start, you may see an error message in the event viewer log.

1. Introduction to the sys module The os module introduced earlier is mainly for the operating system, while the sys module in this article is mainly for the Python interpreter. The sys module is a module that comes with Python. It is an interface for interacting with the Python interpreter. The sys module provides many functions and variables to deal with different parts of the Python runtime environment. 2. Commonly used methods of the sys module. You can check which methods are included in the sys module through the dir() method: import sys print(dir(sys))1.sys.argv-Get the command line parameters sys.argv is used to implement the command from outside the program. The program is passed parameters and it is able to obtain the command line parameter column

Preface This article continues to introduce the Python collection module. This time it mainly introduces the named tuples in it, that is, the use of namedtuple. Without further ado, let’s get started – remember to like, follow and forward~ ^_^Creating named tuples The named tuple class namedTuples in the Python collection gives meaning to each position in the tuple and enhances the readability of the code Sexual and descriptive. They can be used anywhere regular tuples are used, and add the ability to access fields by name rather than positional index. It comes from the Python built-in module collections. The general syntax used is: import collections XxNamedT

The working principle of Ansible can be understood from the above figure: the management end supports three methods of local, ssh, and zeromq to connect to the managed end. The default is to use the ssh-based connection. This part corresponds to the connection module in the above architecture diagram; you can press the application type HostInventory (host list) classification is carried out in other ways. The management node implements corresponding operations through various modules. A single module and batch execution of a single command can be called ad-hoc; the management node can implement a collection of multiple tasks through playbooks. Implement a type of functions, such as installation and deployment of web services, batch backup of database servers, etc. We can simply understand playbooks as, the system passes

All data are automatically assigned a "DOB" (Date of Birth) at the beginning. Therefore, it is inevitable to encounter date and time data when processing data at some point. This tutorial will take you through the datetime module in Python and using some peripheral libraries such as pandas and pytz. In Python, anything related to date and time is handled by the datetime module, which further divides the module into 5 different classes. Classes are simply data types that correspond to objects. The following figure summarizes the 5 datetime classes in Python along with commonly used attributes and examples. 3 useful snippets 1. Convert string to datetime format, maybe using datet

Hello, my name is somenzz, you can call me Brother Zheng. Python's import is very intuitive, but even so, sometimes you will find that even though the package is there, we will still encounter ModuleNotFoundError. Obviously the relative path is very correct, but the error ImportError:attemptedrelativeimportwithnoknownparentpackage imports a module in the same directory and a different one. The modules of the directory are completely different. This article helps you easily handle the import by analyzing some problems often encountered when using import. Based on this, you can easily create attributes.

In CTR estimation, the mainstream method uses feature embedding+MLP, in which features are very critical. However, for the same features, the representation is the same in different samples. This way of inputting to the downstream model will limit the expressive ability of the model. In order to solve this problem, a series of related work has been proposed in the field of CTR estimation, which is called feature enhancement module. The feature enhancement module corrects the output results of the embedding layer based on different samples to adapt to the feature representation of different samples and improve the expression ability of the model. Recently, Fudan University and Microsoft Research Asia jointly published a review on feature enhancement work, comparing the implementation methods and effects of different feature enhancement modules. Now, let us introduce a
