This section applies to ThinkPHPV2.0. in version 3.0, Generic Routing has been changed to regular routing. If you need to know the routes of other versions, refer to: This section applies to ThinkPHP V2.0, in 3.0
In version, the generic route has been changed to a regular route. For more information about routes of other versions, see:
ThinkPHP 3.0 regular routing
ThinkPHP 2.1
Routing
ThinkPHP URL Generic Routing
A wildcard route provides support for multiple rules for the same route name, so that the URL
Is more flexible. For example:
A URL like a http://www.phplo.com/index.php/product/123
Address
The actual address accessed is the http://www.phplo.com/index.php/Products/show/product_id/123
While
A url such as a http://www.phplo.com/index.php/product/2010/10, the address actually accessed is
Http://www.phplo.com/index.php/Products/archive/year/2010/month/10
Generic Routing definition and instance
Generic Routing syntax definition
In a wildcard routing rule, you must use a PHP regular expression to match the route. the specific syntax rules are as follows:
- Return array (
- // Generic Routing
- 'Routename @ '=> array (
- Array ('Route matching regularize', 'Module name', 'Operation name', 'parameter defining', 'additional parameter '),
- ),
- )
Prompt
If you are using ThinkPHP 2.1RC
For more information, see ThinkPHP 2.1 URL routing rule comparison 2.0.
Version change.
Generic Routing instance
Taking the example started in this article as an example, the wildcard routing configuration is as follows:
- Return array (
- // Generic Routing
- 'Product @ '=> array (
- Array ('/^ \/(\ d +) $/', 'products', 'show ', 'product _ id '),
- Array ('/^ \/(\ d +) $/', 'products', 'archive', 'Year, month '),
- ),
- )
In a wildcard routing rule, use a regular expression to match a URL
The string behind the route name in the address, which is in red as follows:
Http://www.phplo.com/index.php/product/2010/10
The use of other parameters is the same as that of conventional routes.
Read more
PHP regular expression