ThinkPHP2.1 (including version 2.1RC) enables brand new URL routing rules. compared with version 2.0, ThinkPHP 2.1 routes have two differences:
ThinkPHP 2.1 (including version 2.1RC) enables all-new URL routing rules
Compared with the current version, there are two differences:
Route configuration method: Supports the configuration of the routes. php file and the configuration file Config. php.
Configure the URL_ROUTE_RULES option
Routing configuration rules.
In addition, in version 2.1, the bug that the routing name cannot use uppercase English characters is also solved.
.
Routes. php file configuration
The routing rules of ThinkPHP 2.1 have been greatly changed. Original rules:
- Return array (
- // Regular route
- 'Route name' => array ('Module name', 'Operation name', 'parameter defining', 'additional parameter '),
- // Generic Routing
- 'Route name @ '=> array (
- Array ('Route matching regularize', 'Module name', 'Operation name', 'parameter defining', 'additional parameter '),
- ),
- )
Changed:
- Return array (
- // Regular route
- Array ('Route name', '[group/] module/operation name', 'Route variable', 'additional parameters ')
- // Generic Routing
- Array ('regularization', '[group/] module/operation name', 'Route variable', 'additional parameter ')
- )
Routing example
Earlier version 2.0
The following is an example of how ThinkPHP routes are used and ThinkPHP routes are used:
- Return array (
- // Regular route
- Array ('product', 'Products/Show', 'Category, product_id ', 'status = 1 ')
- // Resolve to group
- Array ('product2', 'admin/Products/Show', 'Category, product_id ', 'status = 1 ')
- // Generic Routing
- Array ('/^ product/(\ d +) $/is', 'Products/archive', 'Year, month ')
- )
It can be seen that the definition rules have been modified. in the generic routing, the regular expression definition matching is performed from APP_NAME
And later than 2.0
The version starts matching after the route name, as shown in red below:
Http://www.phplo.com/index.php/product/2010/10
Added the PHP regular expression modifier.
I (case-insensitive) and s (the string is regarded as a line, and the line break is matched as a normal character). This is required or not. For more information about regular expressions, see PHP
Regular expression.
Config. php file configuration
In addition to routing configuration in the routes. php file
In Config. php, use the URL_ROUTE_RULES project to set the rules. The rules are consistent:
- 'URL _ ROUTE_RULES '=> array (
- Array ('product', 'Products/Show', 'Category, product_id ', 'status = 1 ')
- Array ('/^ product/(\ d +) $/is', 'Products/archive', 'Year, month ')
- ),
If the routes. php file is configured
The routing definition in the routes. php file configuration.
In general, ThinkPHP 2.1
The version of the route configuration is more unified and concise in the configuration rules. It also provides direct routing configuration in the configuration file Config. php.