【发布时间】:2012-02-12 21:53:28
【问题描述】:
我们有一家社交网络初创公司,我们需要集成 smarty 模板。我有一个 php 数组,即 $profile_tasks 。 $profile_tasks 中的元素具有以下属性;
[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 数组中的值不正确。我应该在内循环中改变什么?任何帮助将不胜感激。
【问题讨论】: