Use of ThinkPHP2.0 Generic Routing (applicable to version 2.0)

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




  1. Return array (
  2. // Generic Routing
  3. 'Routename @ '=> array (
  4. Array ('Route matching regularize', 'Module name', 'Operation name', 'parameter defining', 'additional parameter '),
  5. ),
  6. )

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:




  1. Return array (
  2. // Generic Routing
  3. 'Product @ '=> array (
  4. Array ('/^ \/(\ d +) $/', 'products', 'show ', 'product _ id '),
  5. Array ('/^ \/(\ d +) $/', 'products', 'archive', 'Year, month '),
  6. ),
  7. )

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

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.