This part of the route seems to be in the actual work not how to design, just in the default settings, in the manual to see part, difficult to understand.
1. Route definition
What does it take to support path_info,path_info to use the routing feature? The manual mentions "to use the routing feature, provided that your URL supports path_info (or a compatible URL pattern, which does not support routing in normal URL mode)," and that the URL supports path_info, not Apache to support Path_info, Degree Niang Talk is also clear, see below:
PathInfo
(PHP 4 >= 4.0.3, PHP 5)
PathInfo--Returns information about the file path
Description
Array pathinfo (string path [, int options])
PathInfo () returns an associative array containing information about path. Includes the following array cells: dirname,basename and extension.
You can specify which cells to return through the parameters options. They include: Pathinfo_dirname,pathinfo_basename and Pathinfo_extension. The default is to return all cells.
Example 1. PathInfo () example
<?php
$path _parts = PathInfo ("/www/htdocs/index.html");
echo $path _parts["DirName"]. "\ n";
echo $path _parts["basename"]. "\ n";
echo $path _parts["extension"]. "\ n";
?>
The example above will output:
/www/htdocs
Index.html
Html
There is no output on my machine, I found php.ini in the PHP installation directory to open the cgi.fix_pathinfo=1, and I can actually output the above content.
But this is just about the use of a function, which is pathinfo this function returns an array of three elements that are
DirName: I understand that the server name plus the path,
BaseName: The name of the file accessed,
Extension: File name extension
After the server is supported, you also need to open the appropriate configuration in the configuration file.
// turn on Route ' url_router_on ' true
This configuration is also defined in the thinkphp\conf\convention.php file, but it can be overridden in the module's configuration file. Then is the definition of routing rules, the matching of the route is based on a first-come first-served order, after the first successful match will not be matched again, but access to the controller and methods in the route, and pass in parameters, to get the results.
The format of a routing rule definition is:' route expression ' = ' + ' routing address and incoming parameter ' or array (' route expression ', ' Routing address ', ' incoming parameters ')
The route expression contains the rule route Ha Zheng the route
Expression examples
Regular Expression/^blog\/(\d+) $/
Rule expression Blog/:id
The routing address represents the address to which the current route expression needs to be routed, contains internal addresses and external addresses, and allows implicitly passed parameters that are not in the URL, allowing the use of strings or arrays to define the routing function, which can be defined in the following 6 ways, by using a closure function.
How to define |
Defining Formats |
Mode 1: route to internal address (string) |
' [Group/module/operation]? extra parameter 1= value 1& extra parameter 2= value 2 ... ' |
Method 2: Route to internal address (array) parameters in string mode |
Array (' [Group/module/operation] ', ' extra parameter 1= value 1& extra parameter 2= value 2 ... ') |
Mode 3: route to internal address (array) parameter in array mode |
Array (' [Group/module/operation] ', array (' extra parameter 1 ' = ' = ' value 1 ', ' extra parameter 2 ' = ' = ' value 2 ' ...) [, routing parameters]) |
Mode 4: route to external Address (string) 301 redirect |
' External address ' |
Mode 5: route to an external address (array) to specify the redirect code |
Array (' External address ', ' redirect code ' [, route parameter]) |
Mode 6: Closure function |
function ($name) {echo ' Hello, '. $name;} |
I don't understand it at all!
Routes that start with HTTP or/are considered to be an external address or redirect address, such as
' Blog/:id ' + '/blog/read/id/:1 ' uses 301 redirect way to Route jumps, this way the advantage is that the URL can be more arbitrary, including in the URL to pass more non-standard format parameters, wipe completely do not understand, non-standard format parameters for what? Too TM Professional.
' blog/:id ' + ' blog/read ': supports only modules and operating addresses, for example we want avatar/123 to be redirected to /member/avatar/id/123_small only using ' Avatar/:id ' = '/member/avatar/id/:1_small ' Looks like: ID represents a parameter, parameter name is ID. If you want to refer to a dynamic variable, the route address is in the form of a : 1, 2
, if you are using a redirect address. The use of redirection to an external address is often useful for the URL migration process after the site has been revised, for example: ' Blog/:id ' + ' http://blog.thinkphp.cn/read/:1 ' represents the current site (possibly HTTP// The blog/123
address of thinkphp.cn) is redirected directly to http://blog.thinkphp.cn/read/123
.