Home >Backend Development >PHP Tutorial >php smarty模板赋值问题

php smarty模板赋值问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:17:53791browse

$arr = array([0]=>array([goods_id]=>1[goods_name]=>手机[goods_price33]=>1000)[1]=>array([goods_id]=>2[goods_name]=>电脑)[goods_price33]=>2000));
$smarty->assign('goods_list',   $arr);
?>


{foreach from=$goods_list item=goods}
{$goods.goods_id}
{$goods.goods_name}
{$goods.goods_price33}      正常显示价格 1000
{/foreach}


问题goods_price33 中的33是个变量,根据会员id的不同显示不同的值
请问如何在模板中实现变化,试了很多方法都不行
比如
$num =$_GET['id']
$smarty->assign(num,  $num);



{foreach from=$goods_list item=goods}
{$goods.goods_id}
{$goods.goods_name}
{$goods.goods_price{$num}}      不正常,浏览器中显示{$goods.goods_price33},不能显示价格
{/foreach}


回复讨论(解决方案)

$num =$_GET['id']
$smarty->assign(num,  $num); 你在这就判断用户id不是更好

逻辑的东西不要放到内容里去

$num =$_GET['id']
$smarty->assign(num,  $num); 你在这就判断用户id不是更好



这段在php脚本文件里面,但是赋值到模板循环中就不行了,其他地方正常

逻辑的东西不要放到内容里去



是没放在内容,可能我没说清楚,那是分开的,php中赋值后,引用到模板循环中不显示值,其他地方可以显示

你应该在php里获取到会员的id显示到数组里,然后赋值到模版,不能直接赋值在模版里。

Statement:
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