tp中u步骤的使用

WBOY
Release: 2016-06-13 12:13:31
Original
1078 people have browsed it

tp中u方法的使用

自学的时候都没怎么使用过该方法,现在刚进入一个新公司参加项目。发现这个方法用的很多,所以记录下来防止以后忘了。

U方法用于完成对URL地址的组装,特点在于可以自动根据当前的URL模式和设置生成对应的URL地址,格式为:

U('地址','参数','伪静态','是否跳转','显示域名');

<span style="color: #008080;">1</span> <span style="color: #008000;">//</span><span style="color: #008000;">比如操作成功跳转到Store模块下的Ump控制器中的lists方法</span><span style="color: #008080;">2</span> <span style="color: #800080;">$this</span>->success('新增成功',U('Strore/Ump/lists'));
Copy after login
<span style="color: #008000;">1 //</span><span style="color: #008000;">跳转时带着参数的话</span><span style="color: #800080;">2 $this</span>->success('新增成功',U('Store/Ump/lists','type=1&id=1'));
Copy after login

当在模板中使用U方法时,好处在于:一旦你的环境变化或者参数设置改变,你不需要更改模板中的任何代码。

在模板中的调用格式需要采用 {:U('地址', '参数'…)} 的方式

<span style="color: #008000;"><!--</span><span style="color: #008000;">在模板中使用U方法 </span><span style="color: #008000;">--></span><span style="color: #000000;">{:U('Store/Ump/lists','type=1</span><span style="color: #ff0000;">&id</span>=1')}
Copy after login

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!