Decryption of ThinkPHP3.1.2 module and Operation ing _ php instance

Source: Internet
Author: User
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:




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.


(Not considering the previously defined module Ing ):


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




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.


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.


After the module and Operation ing are used, the routing definition of the relevant URL address may need to be adjusted.

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: 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.