duanjiaolao1187
2015-03-25 21:16
浏览 49
已采纳

如何在smarty中循环访问对象

I have a script which is passing an object array to smarty like so:

$smarty->assign('results', $user->results());

The array looks like this:

Array
(
[0] => stdClass Object
    (
        [id] => 1
        [agency_name] => Agency #1
        [created_date] => 2015-03-25 20:23:44
    )

[1] => stdClass Object
    (
        [id] => 2
        [agency_name] => gggg
        [created_date] => 2015-03-25 21:26:06
    )

)

How can I loop through this object array using smarty? I have tried something like this, with no luck..

{section name="i" loop=$result}
{$result[i]->id}
{/section}

Any ideas?

Thanks

图片转代码服务由CSDN问答提供 功能建议

我有一个脚本将对象数组传递给smarty,如下所示:</ p> < pre> $ smarty-&gt; assign('results',$ user-&gt; results()); </ code> </ pre>

数组如下所示:< / p>

  Array 
(
 [0] =&gt; stdClass Object 
(
 [id] =&gt; 1 
 [agency_name] =&gt;代理商#1  
 [created_date] =&gt; 2015-03-25 20:23:44 
)
 
 [1] =&gt; stdClass对象
(
 [id] =&gt; 2 
 [agency_name]  =&gt; gggg 
 [created_date] =&gt; 2015-03-25 21:26:06 
)
 
)
 </ code> </ pre> 
 
 

我该怎么办? 使用smarty循环遍历此对象数组? 我尝试过这样的事情,没有运气.. </ p>

  {section name =“i”loop = $ result} 
 {$ result [i]  - &gt; id  } 
 {/ section} 
 </ code> </ pre> 
 
 

任何想法?</ p>

谢谢</ p> </ div>

2条回答 默认 最新

相关推荐 更多相似问题