thinkphp function: U method

Source: Internet
Author: User
Tags subdomain

The U method is used to complete the assembly of URL addresses, which is characterized by the ability to automatically generate corresponding URL addresses based on the current URL pattern and settings, in the following format:
U (' address ', ' parameters ', ' pseudo-static ', ' whether Jump ', ' Show domain name ');
The advantage of using the U method instead of a fixed write dead URL in a template is that once your environment changes or the parameter settings change, you don't need to change any of the code in the template.
The calling format in the template requires the use of the {: U (' address ', ' Parameters ' ...)}The way

Examples of usage of the Basic usage U method:
    1. U(' User/add ') //Generate Add Action address for User module
You can also support grouping calls:
    1. U(' Home/user/add ') //Generate the Add action address of the User module for the Home group
Of course, it can be just a write operation name, which means that the current module is called
    1. U(' Add ') //Generate Add action address for current access module
In addition to grouping, modules, and operation names, we can also pass in some parameters:
    1. U(' blog/read?id=1 ') //Generate a read operation for the Blog module and a URL address with ID 1
The second parameter of the U method supports passing arguments, supports both array and string definitions, and if only a string-only parameter can be defined in the first argument, the following are equivalent:
    1. U(' blog/cate ',array(' cate_id '=1,' status '=1))
    2. U(' blog/cate ',' Cate_id=1&status=1 ')
    3. U(' Blog/cate?cate_id=1&status=1 ')
However, it is not allowed to use the following definition to pass parameters:
    1. U(' blog/cate/cate_id/1/status/1 ')
Depending on the URL settings of the project, the same U method call can intelligently correspond to different URL address effects, for example:
    1. 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:
    1. HTTP://servername/index.php?m=blog&a=read&id=1
If the current URL is set to PathInfo mode, the last URL generated by the same method is:
    1. HTTP://servername/index.php/blog/read/id/1
If the current URL is set to rewrite mode, the last URL generated by the same method is:
    1. HTTP://servername/blog/read/id/1
If you also set the PathInfo delimiter:
    1. ' Url_pathinfo_depr '= '_ '
Will generate
    1. 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 last URL generated by the same method is:
    1. HTTP://servername/blog/read/id/1.html
If more than one pseudo-static support is set, the first pseudo-static suffix is automatically appended to the URL address, but you can also manually specify the pseudo-static suffix to be generated in the U method, for example:
    1. U(' Blog/read ',' id=1 ',' xml ')
Will generate
    1. HTTP://servername/blog/read/id/1.xml
The route support U method can also support routing if we define a routing rule for:
    1. ' news/:id\d '= 'news/read '
Then you can use
    1. U('/news/1 ')
The resulting URL address is:
    1. HTTP://servername/index.php/news/1
Domain support If your app involves more than one subdomain's operating address, you can also specify the domain name in the U method that needs to generate the address, for example:
    1. U(' blog/[email protected] ',' id=1 ');
After the @ is passed in to 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 subdomain that generated the current address according to the subdomain deployment settings App_sub_domain_deploy and App_sub_domain_rules automatically.
If Url_case_insensitive is turned on, a lowercase URL address is generated uniformly. The anchor supports the 3.1.2 version, and the U method can also support the generation of anchor points in the URL address, for example:
    1. U(' blog/read#comment ',' id=1 ',' HTML ')
Will generate
    1. HTTP://servername/blog/read/id/1.html#comment
If the domain name and anchor point are used at the same time, note that the order is the first anchor point after the domain name, for example:
    1. U(' blog/read#[email protected] ',' id=1 ');

thinkphp function: U method

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.