Usage of the U method in ThinkPHP

Source: Internet
Author: User

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..

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.