implementation of the U-method of the Thinkphp development series-Simple implementation URL

Source: Internet
Author: User

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 call format in the template needs to take the form {: U (' address ', ' Parameters ' ...)}

U (' user/add ')//Generate Add Action address for User module

  

U (' home/user/add ')//Generate the Add action address of the User module for the Home group

  

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

  

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

  

U (' Blog/read ', array (' ID ' =>1) '//array to implement

Of course it can be done.

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:

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, it is not allowed to use the following definition to pass parameters:

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

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:

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

  

implementation of the U-method of the Thinkphp development series-Simple implementation URL

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.