Usage of the U method in ThinkPHP _ php instance

Source: Internet
Author: User
This article mainly introduces the use of the U method in ThinkPHP. For more information, see the following definition rules for the U method in thinkPHP ):

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