ThinkPHP的模版中什么时候需要在方法前加冒号,什么时候不需要加?

WBOY
Release: 2016-06-06 20:21:44
Original
1414 people have browsed it

比如,我在导航中想链接到首页:
写成这样:"{U('Index/Index')}"
不能正确链接到首页。
写成这样才行:"{:U('Index/Index')}"
(即U方法前加了冒号)

但是,我在另一个地方,一个form表单中:


U方法前加不加冒号都没有问题!

为什么会这样?

回复内容:

比如,我在导航中想链接到首页:
写成这样:"{U('Index/Index')}"
不能正确链接到首页。
写成这样才行:"{:U('Index/Index')}"
(即U方法前加了冒号)

但是,我在另一个地方,一个form表单中:


U方法前加不加冒号都没有问题!

为什么会这样?

1、 U() 是ThinkPHP中生成URL的函数
2、 在模板中,使用 {:U('home/index')} 这种方式意为: <?php echo :U('home/index') ?>
3、 如果仅仅是写 {U('home/index')} 应该是会被理解为无效的(也有可能是执行了但没有echo),没有具体测试过;而LZ说的在form中加不加冒号都没有问题可能是因为这样写无效,没有输出任何东西,所以就变成了 <form ... action=""></form>,而在form标记中,action为空是默认提交到当前页面的。 so ..

链接描述

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!