Provides various official and user-released code examples. For code reference, you are welcome to learn. The U method is the method used in ThinkPHP to automatically generate URL addresses, it can help you automatically generate the corresponding URL address for different environments and configurations.
Features:
1. automatically identify the current URL Mode
2. automatically identifies the current PATH_INFO Separator
3. Support for domain names and second-level domain names
4. Support for pseudo-static and anchor
5. Route address support
Therefore, when using the U method, you basically do not need to pay attention to what URL mode and configuration parameters are currently used, and you can call them according to the uniform rules of the U method, the U method will automatically recognize the actual generated URL address.
Below are some basic usage:
// Read operation address of the current module. The input parameter id is 5.
U ('read', 'Id = 5 ');If you want to input a variable, use:
U('read','id='.$vo['id']);If your U method is called in the template, it should be written:
Read articlesGenerate the index operation address of the Blog module and input more parameters:
U('blog/index','cate_id=5&type=1');Of course, you can also use arrays to pass parameters:
U('blog/index',array('cate_id'=>5,'type'=>1));If the number of parameters is small, you can also directly input the following in the first parameter:
U('Blog/read?id=5');
U('Blog/cate?cate_id=1&status=1')Supports group generation:
U ('home/Blog/read? Id = 5'); // The read operation address of the blog module under the Home Group
U ('admin/Blog/cate? Cate_id = 1 & status = 1'); // Admin GroupIndicates
The U method will automatically add the current pseudo-static suffix. If you have configured multiple pseudo-static suffixes, the first suffix will be added by default. If you need to specify the pseudo-static suffix, you can also use:
U('Blog/read','id=1','xml');The URL with the suffix of. xml.
If you want to use the U method to output the route address, you need to add "/" before the first parameter, for example:
U('/news/1');The URL to be generated is a route address such as news/1.
To generate a URL with a domain name, you can use:
U('Blog/read@blog.thinkphp1.cn','id=1');Or
U('Blog/read@blog','id=1');Indicates that the second-level domain name address of the current domain name is used.
Support generation of anchor points (note that only the latest Git version is supported)
U('Blog/read#review','id=5');The generated URL address is appended with the # review anchor to facilitate jump to the comment section.
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB