Thinkphp URL routing rules and configuration instance _ php instance

Source: Internet
Author: User
This article mainly introduces thinkphp URL routing rules and configuration methods, analyzes ThinkPHP routing rules and pseudo-static setting methods, and analyzes relevant precautions, thinkPHP is a very important technique in development. if you need thinkphp, you can refer to the examples in this article to describe ThinkPHP URL routing rules and configuration methods. Share it with you for your reference. The specific analysis is as follows:

I. URL rules

1. the default value is case sensitive.

2. you can change the configuration file if you do not want to be case sensitive.

The code is as follows:

'URL _ CASE_INSENSITIVE '=> true, // The URL is case insensitive.


3. if the module name is UserGroupAction, you need to write the url to the module.

The code is as follows:

Http: // localhost/thinkphp4/index. php/user_group/index

4. if 'URL _ CASE_INSENSITIVE '=> false, the URL can also be written

The code is as follows:

Http: // localhost/thinkphp4/index. php/UserGroup/index

II. URL pseudo-static

The code is as follows:

'URL _ HTML_SUFFIX '=> 'HTML | shtml | XML', // restrict pseudo-static suffixes

III. URL routing

1. start the route

To enable route support in the configuration file

The code is as follows:

'URL _ ROUTER_ON '=> ture // enable routing

2. use routing

1. configure routes using rule expressions

The code is as follows:

'URL _ route_rules' => array () // routing rules
'My => 'index/Index', // static address routing
'My => '/Index/Index', // static address routing, and add/directly to the root directory of the website.
': Id/: num' => 'index/Index', // dynamic address routing. you can use $ _ GET to receive parameters in the address bar.
'Year/: year/: month/: date' => 'index/Index', // dynamic and static hybrid address routing
'Year/: year \ d/: month \ d/: date \ d' => 'index/Index ', // add \ d to the dynamic and static hybrid address routing to indicate that the type can only be numbers
'My/: id $ '=> 'index/Index', // add $ to indicate that the address can only be my/1000 followed by no other content


2. configure the route using a regular expression, which must start/end/

The code is as follows:

'/^ Year \/(\ d {4}) \/(\ d {2}) \/(\ d {2})/' => 'index/Index? Year =: 1 & month =: 2 & date =: 3' // Here \ d indicates that it must be a number

3. notes:

1. the more complex the route is, the more advanced it is.

The code is as follows:

'URL _ ROUTE_RULES '=> array (
'My/: year/: month:/: day' => 'index/Day ',
'My/: id \ d' => 'index/Index ',
'My/: name' => 'index/Index ',
)


2. you can use $ as a completely matched routing rule.

The code is as follows:

'URL _ ROUTE_RULES '=> array (
'My/: id \ d $ '=> 'index/Index ',
'My/: name $ '=> 'index/Index ',
'My/: year/: month: //: day $ '=> 'index/Day ',
),


3. use the regular expression matching to start with/^ and end with $ /.

The code is as follows:

'URL _ ROUTE_RULES '=> array (
'/^ My \/(\ d +) $/' => 'Index/index? Id =: 1 ',
'/^ My \/(\ w +) $/' => 'Index/index? Name =: 1 ',
'/^ My \/(\ d {4}) \/(\ d {2}) \/(\ d {2 }) $/'=> 'index/day? Year =: 1 & month =: 2 & day =: 3 ',
),

I hope this article will help you build ThinkPHP.

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.