1
我们有一个社交网络启动,我们需要集成smarty模板。我有一个PHP阵列,即$profile_tasks
。 $profile_tasks
中的元素具有以下属性;Smarty打印评论给出了多维数组中的错误值
[0] => Array
(
[name] => hello
[location] =>
[date] =>
[time3] => 0
[time1] =>
[state] => 0
[like_count] => 0
[comment_count] => 2
[does_id] => 91
[comments] => Array
(
[sender_id] => 27
[content] => khhkhjkkhk
[time] => 2012-02-09 20:06:13
[user_name] => aacanakin
[picture_url] => http://graph.facebook.com/fb_user_name/picture
)
)
在我的Smarty的模板文件,我已经分配$profile_tasks
阵列像这样;
$smarty->assign("profile_tasks", $profile_tasks);
在我.tpl文件中,有在打印任何像[name]
或[location]
字段属性都没有问题。我有以下用于名称打印的代码;
{foreach name=outer item=profile_task from=$profile_tasks}
{$profile_task.name}
{$profile_task.locatin} // these two works correctly
{foreach name=inner item=comment from=$profile_task.comments}
{comment.user_name} // these three statements doesn't return correct values
{comment.picture_url}
{comment.content}
{/foreach}
{/foreach}
所以,正如我前面所述,comments
数组内的值是不正确的。我应该在内循环中改变什么?任何帮助将不胜感激。
评论有多个值。这就是为什么我需要内部foreach – aacanakin 2012-02-12 13:02:28
评论没有你的数组中的多个值。改正你的数组,你的代码将起作用。 – 2012-02-12 13:04:19
profile_tasks数组可以有多个注释。这个例子不包含多个注释。我将编辑帖子。 – aacanakin 2012-02-12 13:06:05