The rules for defining the U method in thinkPHP are as follows (the parameters in square brackets are determined based on the actual application ):
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: // <serverName>/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: // <serverName>/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: // <serverName>/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: // <serverName>/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: // <serverName>/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..