thinkphp Development Framework function Detailed: U method

Source: Internet
Author: User
Keywords Development framework function Thinkphp u method
Tags .url address blog change code development development framework display

The U method is used to assemble the URL address, which is characterized in that it can automatically generate the corresponding URL address based on the current URL pattern and settings:
U (' address ', ' parameter ', ' pseudo static ', ' Jump ', ' Show domain name ');
The advantage of using the U method in a template instead of fixing a dead URL address is that you don't need to change any of the code in the template once your environment changes or the parameter settings change.
The calling format in the template requires the way {: U (' address ', ' parameter ' ...)}
Examples of the use of the U method:

U (' User/add ') &http://www.aliyun.com/zixun/aggregation/37954.html ">nbsp;//generate add Operation address for User module

You can also support group calls:

U (' home/user/add ')//Generate add Operation address of User module for home grouping

Of course, you can just write the name of the operation, which means the call to the current module

U (' add ')//Generate add operation address for current access module

In addition to grouping, module, and operation names, we can pass in some parameters:

U (' blog/read?id=1 ')//generate the read operation of the Blog module and URL address with ID 1

The second parameter of the U method supports the passed-in arguments, supports both arrays and strings, and is equivalent if only the parameters of the string method can be defined in the first argument:

U (' blog/cate ', Array (' cate_id ' =>1, ' status ' =>1)) u (' blog/cate ', ' Cate_id=1&status=1 ') u (' Blog/cate?cate_ Id=1&status=1 ')

However, the following definition is not allowed to be used to pass parameters:

U (' BLOG/CATE/CATE_ID/1/STATUS/1 ')

Depending on the URL settings of the project, the same U-method invocation can intelligently correspond to different URL-address effects, for example:

U (' blog/read?id=1 ')

This definition is an example.
If the current URL is set to normal mode, the last generated URL address is:

Http://serverName/index.php?m=Blog&a=read&id=1

If the current URL is set to PathInfo mode, the same method finally generates the URL address:

Http://serverName/index.php/Blog/read/id/1

If the current URL is set to rewrite mode, the same method finally generates the URL address:

Http://serverName/Blog/read/id/1

If you also set the PathInfo separator:

' Url_pathinfo_depr ' => ' _ '

Will generate

Http://serverName/Blog_read_id_1

If the current URL is set to rewrite mode and the pseudo static suffix is set to HTML, the same method finally generates the URL address:

Http://serverName/Blog/read/id/1.html

If multiple pseudo static support is set, the first pseudo static suffix is automatically added to the URL address, but you can also manually specify the pseudo static suffix to be generated in the U method, for example:

U (' Blog/read ', ' id=1 ', ' xml ')

Will generate

Http://serverName/Blog/read/id/1.xml

The U method can also support routing if we define a routing rule that is:

' news/:id\d ' => ' news/read '

Then you can use

U ('/NEWS/1 ')

The resulting URL address is:

Http://serverName/index.php/news/1

If your application involves multiple subdomains, you can also specify the domain name in the U method that requires the address to be generated, for example:

U (' blog/read@blog.thinkphp.cn ', ' id=1 ');

@ then pass in the domain name you want to specify.
In addition, the 5th parameter of the U method, if set to true, indicates that the current domain name is automatically recognized and automatically matches the App_sub_domain_deploy and app_sub_domain_rules that generate the current address based on the child domain name deployment settings.
If Url_case_insensitive is turned on, a lowercase URL address is generated uniformly.

Related Article

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.