Comparison between ThinkPHP2.1 URL routing rules and version 2.0

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




  1. Return array (
  2. // Regular route
  3. 'Route name' => array ('Module name', 'Operation name', 'parameter defining', 'additional parameter '),

  4. // Generic Routing
  5. 'Route name @ '=> array (
  6. Array ('Route matching regularize', 'Module name', 'Operation name', 'parameter defining', 'additional parameter '),
  7. ),
  8. )

Changed:




  1. Return array (
  2. // Regular route
  3. Array ('Route name', '[group/] module/operation name', 'Route variable', 'additional parameters ')

  4. // Generic Routing
  5. Array ('regularization', '[group/] module/operation name', 'Route variable', 'additional parameter ')
  6. )

Routing example

Earlier version 2.0
The following is an example of how ThinkPHP routes are used and ThinkPHP routes are used:




  1. Return array (
  2. // Regular route
  3. Array ('product', 'Products/Show', 'Category, product_id ', 'status = 1 ')
  4. // Resolve to group
  5. Array ('product2', 'admin/Products/Show', 'Category, product_id ', 'status = 1 ')

  6. // Generic Routing
  7. Array ('/^ product/(\ d +) $/is', 'Products/archive', 'Year, month ')
  8. )

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:




  1. 'URL _ ROUTE_RULES '=> array (
  2. Array ('product', 'Products/Show', 'Category, product_id ', 'status = 1 ')
  3. Array ('/^ product/(\ d +) $/is', 'Products/archive', 'Year, month ')
  4. ),

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.

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.