折雨的天空
smarty3里的foreach需要注意的一点
2011-11-2 我好笨

今天无意中发现这样一个问题,在smarty 3,测试版本号为Smarty 3.1.4。



在使用新的foreach语法时如果使用如下代码会得到错误信息:



<{foreach $sites as $k=>$sites}>

错误信息如下:





Fatal error: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "E:/www/cai/templates\index.html" on line 30 "&lt;{foreach $sites as $k=&gt;$sites}&gt;" item variable 'sites' may not be the same variable as at 'from'' in 




正确的写法是:



<{foreach $sites as $k=>$v}>



看来,smarty的foreach虽然和PHP的越来越接近了,但是毕竟它还是不是PHP。









评论:
南宁音响
2012-09-11 17:27 回复
真的不懂
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容