Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the u method of thinkphp

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how to use the u method of thinkphp". In the daily operation, I believe that many people have doubts about how to use the u method of thinkphp. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "how to use the u method of thinkphp"! Next, please follow the editor to study!

Thinkphp's u method is used to assemble URL addresses, which is characterized in that it can automatically generate corresponding URL addresses according to the current URL mode and settings. The syntax is "U ('address', 'parameter', 'pseudo-static', 'whether to jump', 'show domain name').

This article operating environment: Windows7 system, ThinkPHP5.0 version, Dell G3 computer.

How to use the u method of thinkphp?

The U method is used to assemble the URL address, which is characterized in that the corresponding URL address can be automatically generated according to the current URL mode and settings, and the format is:

U ('address', 'parameter', 'pseudo-static', 'whether to jump', 'show domain name')

The advantage of using the U method in a template instead of writing a dead URL address is that once your environment changes or parameter settings change, you don't need to change any code in the template.

The call format in the template needs to be {: U ('address', 'parameter'...) The way of}

Basic usage

An example of the usage of the U method:

You can also support grouping calls:

U ('Home/User/add') / / add operation address of the User module that generates the Home packet

Of course, you can just write the operation name to indicate that the

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

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

The second parameter of the U method supports input parameters and supports both array and string definition. If only a string parameter can be defined in the first parameter, the following methods are equivalent:

U ('Blog/cate',array (' Blog/cate','cate_id=1&status=1') U ('Blog/cate?cate_id=1&status=1') (' Blog/cate','cate_id=1&status=1') U)

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, such as for:

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

This definition is taken as an example.

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

If the current URL is set to PATHINFO mode, the final URL address generated by the same method is:

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

If the current URL is set to REWRITE mode, the final URL address generated by the same method is:

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

If you also set the PATHINFO delimiter:

'URL_PATHINFO_DEPR'= >'_'

Will be generated.

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 final URL address generated by the same method is:

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. Of course, 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 be generated.

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

Routing support

'news/:id\ dcast = >' News/read'

Then you can use the

U ('/ news/1')

The resulting URL address is:

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

Domain name support

If your application involves the operation addresses of multiple sub-domain names, you can also specify the domain name to generate the address in the U method, for example:

U ('Blog/read@blog.thinkyisu.com','id=1')

@ and then pass in the domain name that needs to be specified.

In addition, if the fifth parameter of the U method is set to true, the current domain name is automatically identified, and the subdomain name of the current address is automatically generated by automatically matching APP_SUB_DOMAIN_DEPLOY and APP_SUB_DOMAIN_RULES according to the subdomain name deployment settings.

If URL_CASE_INSENSITIVE is enabled, lowercase URL addresses are uniformly generated.

Anchor support

Starting with version 3.1.2, the U method can also support the generation of anchor points in URL addresses, such as:

U ('Blog/read#comment','id=1','html')

Will be generated.

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 anchor point before domain name, for example:

U ('Blog/read#comment@blog','id=1')

At this point, the study of "how to use the u method of thinkphp" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report