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

  • 写回答

2条回答 默认 最新

  • duanhuiuw12555 2015-03-26 11:37
    关注

    I managed to get it working using smarty assign_by_ref

    $smarty->assign_by_ref('object', $object)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 树莓派5做人脸情感识别与反馈系统
  • ¥15 selenium 控制 chrome-for-testing 在 Linux 环境下报错 SessionNotCreatedException
  • ¥15 使用pyodbc操作SQL数据库
  • ¥15 MATLAB实现下列
  • ¥30 mininet可视化打不开.mn文件
  • ¥50 C# 全屏打开Edge浏览器
  • ¥80 WEBPACK性能优化
  • ¥30 python拟合回归分析
  • ¥500 metaswitch 6010
  • ¥15 关于#分类#的问题:不用人工智能的算法