This article mainly introduces the use of the U method in ThinkPHP. For more information, see the following definition rules for the U method in thinkPHP ):
U ('[Project: //] [route @] [group name-module/] operation? Parameter 1 = value 1 [& parameter N = value N] ')
You can also input parameters using arrays:
U ('[Project: //] [route @] [group name-module/] operation', array ('Parameter 1' =>' value 1 '[, 'parameter n' =>' value n'])
If no project or module is defined, the current project and module name are displayed.Below are some simple examples:
U ('myapp: // User/add') // Generate the URL of the add operation for the User module of the Myapp project
U ('blog/read? Id = 1') // The URL of the read operation that generates the Blog module and whose id is 1
U ('admin-User/select') // Generate the URL of the select operation for the User module of the Admin group
Are you sure you want to use the parameter? Id = 1 & name = tp or arrayIn some cases, although U ('blog/read/id/1') and U ('blog/read? Id = 1 '), but different URL settings may cause resolution errors.
Based on different URL settings of the project, the same U method call can intelligently correspond to different URL address effects.For example, for U ('blog/read? Id = 1.
If the current URL is set to normal mode, the last generated URL address is:
HTUhttp :// /Index. php? M = Blog & a = read & id = 1UTH
If the current URL is set to PATHINFO, the last URL generated by the same method is:
HTUhttp :// /Index. php/Blog/read/id/1UTH
If the current URL is set to REWRITE mode, the last URL generated by the same method is:
HTUhttp :// /Blog/read/id/1UTH
If urlsets the format to rewriteand the pseudo-static suffix to .html, the last URL generated by the same method is:
HTUhttp :// /Blog/read/id/1.html UTH
In addition,The U method also supports routing.If we define a route named View, pointing to the read operation of the Blog module, the parameter is id, then U ('View @? The generated URL address is:
HTUhttp :// /Index. php/View/id/1UT
Note:The routing of the U method supports only simple routing, but does not support wildcard routing or regular routing..