Sample code to decrypt the module and operation map of the ThinkPHP3.1.2 version

Source: Internet
Author: User
Tags decrypt
The template and Operation mapping feature is a mapping mechanism for module and operation settings supported by the ThinkPHP3.1.2 version, which enhances the security of the application by changing the configuration dynamically (real change, not alias) URL access address, and the mapping mechanism has the feature of URL case-insensitive access, which is also very A big help.

Because, under normal circumstances, if you need to change the URL of the module or operation access, the number of files that need to be changed, it is easy to cause association error. In particular, many applications need to migrate to the new version, because of the model and controller changes, resulting in a large number of URL address adjustment, through the module and operation mapping function, it is easy to solve such problems.

1. Module mapping

To define the module mappings, we only need to define them in the configuration file:

' Url_module_map ' =>array (  ' user '   = ' Member ',  ' blog '   = ' Info ')

Url_module_map is an array in which each array item represents:

' Module map name ' = ' Actual module name '

The map name is not case sensitive, so after the URL is set, access from the original:

Http://serverName/index.php/Member/indexhttp://serverName/index.php/Info/index

has become:

Http://serverName/index.php/user/indexhttp://serverName/index.php/blog/index

And the original access URL is invalidated, which is one of the differences between a URL that defines how the route is changed. The module that does not define the mapping is accessed unchanged.
Once the module mapping is defined, the URL name of the current module can be read through the Module_alias constant.

2. Operation Mapping

Not only can the module name be mapped, but the operation name also supports mapping, and is set for the module, which is defined in the following way:

' Url_action_map ' =>array ('  Member ' + =  Array (    ' register ' = = ' add ',    ),  ' Info '   = Array (    ' list '   = = ' Index '    ),

The Url_action_map parameter is a two-dimensional array, with each array item representing:

' Actual module name ' =>array (  ' operation map name 1 ' + ' = ' actual operation name 1 '  operation map Name 2 ' = ' actual operation name 2 '  ...)

Operation map names are case-insensitive, as defined above, URL access from

Http://serverName/index.php/Member/addhttp://serverName/index.php/Info/index

becomes (regardless of the previously defined module mappings):

Http://serverName/index.php/Member/registerhttp://serverName/index.php/Info/list

Similarly, the original URL address access is invalidated. There is no change to the operation access address that defines the map.
Once the operation map is defined, the operation name in the URL address of the current operation can be read through the Action_alias constant.
Operation mappings and module mappings can be defined at the same time, with no impact, such as:

' Url_module_map ' =>array (  ' user '   = ' Member ',), ' Url_action_map ' =>array (  ' Member '  = Array (    ' register888 ' = ' add ',    ),)

Then, the original registered address

Http://serverName/index.php/Member/add

Become a

http://serverName/index.php/user/register888

3.U function Auto Support

Many people may worry that after you set up the module and the operation map, the U function will have to change the situation. In fact, there is no need to worry, because the inside of the U function automatically supports the case of module and operation Mapping.
For example, the original file used in the template

User Registration

Regardless of the mapping of the member module to the add operation, the notation of the U method always remains the same, and it still points correctly to the mapped URL address.

Summarize:

Modules and operation mappings can be used for the following scenarios:

1, there are frequent changes in the URL needs of the occasion
2, the security of the high-URL occasions
3. Applications requiring porting do not want to change the URL address of the occasion

Things to keep in mind:

after the module and operation mappings are used, the routing definition for the associated URL address may need to be adjusted .


http://www.bkjia.com/PHPjc/825438.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/825438. The htmltecharticle template and Operation mapping feature is a mapping mechanism for module and operation settings supported by the ThinkPHP3.1.2 version, as it can be changed dynamically by changing the configuration (actually changing, not aliases) ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.