Home >PHP Framework >ThinkPHP >The definition and use of thinkphp framework routing

The definition and use of thinkphp framework routing

藏色散人
藏色散人Original
2019-07-06 14:28:256863browse

The definition and use of thinkphp framework routing

The definition and use of thinkphp framework routing

The specific and powerful route definition function of ThinkPHP framework can basically meet the needs of All requirements for website routing, including rule routing, regular routing, static routing, and closure support for routing.

The following introduces the definition and use of ThinkPHP framework routing.

Routing definition

Enable routing. Three conditions need to be met for ThinkPHP routing configuration to take effect:

(1) Enable the routing function in the configuration file, as shown in Figure 1;

(2) The URL supports PATH_INFO mode or is compatible with URL mode;

(3) Use the URL_ROUTE_RULES parameter in the configuration file to configure, as shown in Figure 2 below.

The definition and use of thinkphp framework routing

Route definition format. There are two defined formats:

(1) 'Routing expression'=>'Routing address and incoming parameters;

(2)array('Routing expression ','routing address','incoming parameters').

The definition and use of thinkphp framework routing

Routing parameter configuration. The function of these parameters is to limit the validity conditions of the defined routing rules. They mainly have three functions, namely restricting URL suffixes, restricting request types, and customizing detection.

The definition and use of thinkphp framework routing

Routing uses

rule routing. Rule routing expressions include static addresses and dynamic addresses, or a combination of both addresses, as shown below.

Note: Parameters starting with ":" in each parameter represent dynamic parameters. For example: id means that the matched parameter can be obtained using $_GET['id'], and :year, :month and :day correspond to $_GET['year'], $_GET['month'] and $ respectively. _GET['day'].

The definition and use of thinkphp framework routing

Regular routing must start with "/". The expression not only supports regular definition, but also supports function filtering.

The definition and use of thinkphp framework routing

#Static routing. The definition of the route in the expression does not contain dynamic parameters. It has high execution efficiency but limited effect. The format of a static route is: [Controller/Operation?] Parameter 1 = Value 1 & Parameter 2 = Value 2.

Note: In order not to affect the traversal efficiency of dynamic routing, static routing is defined using URL_MAP_RULES to distinguish it from dynamic routing.

The definition and use of thinkphp framework routing

Use closures to define routes. This method does not require the execution of the controller's operation method, as shown below.

The definition and use of thinkphp framework routing

This article comes from the ThinkPHP framework technical article column: http://www.php.cn/phpkj/thinkphp/

The above is the detailed content of The definition and use of thinkphp framework routing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn