I didn’t use this method much when I was studying on my own, and now I have just joined a new company to participate in a project. I found that this method is used a lot, so I recorded it to prevent forgetting it later.
TheU method is used to complete the assembly of URL addresses. Its feature is that it can automatically generate the corresponding URL address based on the current URL mode and settings. The format is:
U('Address', 'Parameters', 'Pseudo-static', 'Whether to jump', 'Display domain name');
<span>1</span> <span>//</span><span>比如操作成功跳转到Store模块下的Ump控制器中的lists方法</span> <span>2</span> <span>$this</span>->success('新增成功',U('Strore/Ump/lists'));
<span>1 //</span><span>跳转时带着参数的话</span> <span>2 $this</span>->success('新增成功',U('Store/Ump/lists','type=1&id=1'));
When using the U method in a template, the advantage is that once your environment changes or parameter settings change, you do not need to change any code in the template.
The calling format in the template needs to be {:U('address', 'parameter'...)}
<span><!--</span><span>在模板中使用U方法 </span><span>--></span><span> {:U('Store/Ump/lists','type=1</span><span>&id</span>=1')}