This article mainly introduces ThinkPHP3.1.2 module and Operation ing. For more information, see the template and Operation ing feature supported by ThinkPHP3.1.2, because the URL access address can be dynamically changed by changing the configuration (actually changed, not an alias), the security of the application is enhanced, and the ing mechanism has the URL-insensitive access feature, it is also helpful for application migration.
Under normal circumstances, if you need to change the URL module or operation access, there are many files to be modified, which may easily lead to association errors. In particular, when many applications need to migrate to the new version, the URL address is greatly adjusted due to many changes to the model and controller. through the module and Operation ing function, you can easily solve such problems.
1. module ing
To define module ING, we only need to define in the configuration file:
'URL_MODULE_MAP'=>array( 'user' => 'Member', 'blog' => 'Info', )
URL_MODULE_MAP is an array. each array item indicates:
'Module ing name' => 'actual module name'
The ing name is case-insensitive. Therefore, after setting the ing name, URL access starts from the original:
http://serverName/index.php/Member/indexhttp://serverName/index.php/Info/index
Changed:
http://serverName/index.php/user/indexhttp://serverName/index.php/blog/index
In addition, the original access URL is invalid, which is one of the differences between changing the URL and defining the routing mode. The access to modules without a ing definition remains unchanged.
After the module ING is defined, the URL name of the current module can be read through the MODULE_ALIAS constant.
2. operation ing
Not only can the module name be mapped, but also the operation name can be mapped. it is set for the module. The operation ING is defined as follows:
'URL_ACTION_MAP'=>array( 'Member' => array( 'register' => 'add', ), 'Info' => array( 'list' => 'index' ), )
The URL_ACTION_MAP parameter is a two-dimensional array. each array item represents:
'Actual module name' => array ('Operation ing name1' => 'actual operation name1' operation ing name2' => 'actual operation name2 '... ...)
The operation ing name is case insensitive.
http://serverName/index.php/Member/addhttp://serverName/index.php/Info/index
(Not considering the previously defined module Ing ):
http://serverName/index.php/Member/registerhttp://serverName/index.php/Info/list
Similarly, the original URL access fails. The operation access address that does not define the ING remains unchanged.
After the operation ING is defined, the operation name of the current operation in the URL address can be read through the ACTION_ALIAS constant.
Operation ING and module ING can be defined at the same time without any impact, for example:
'URL_MODULE_MAP'=>array( 'user' => 'Member', ), 'URL_ACTION_MAP'=>array( 'Member' => array( 'register888' => 'add', ), )
Then, the original registration address
http://serverName/index.php/Member/add
Changed
http://serverName/index.php/user/register888
3. The U function is automatically supported.
Many may worry that after the module and Operation ING is set, the U function will need to be changed accordingly. In fact, you don't need to worry about it because the U function automatically supports module and Operation ING.
For example
User registration
Regardless of how to define the ing between the Member module and the add operation, the write method of the U method remains unchanged and still correctly points to the mapped URL address.
Summary:
Module and Operation ING can be used in the following scenarios:
1. frequent URL changes
2. high URL security
3. applications to be transplanted do not want to change the URL address.
Note:
After the module and Operation ing are used, the routing definition of the relevant URL address may need to be adjusted.