在SugarCRM中通过Smarty迭代一个数组

时间:2013-08-06 21:32:53

标签: smarty sugarcrm

在Smarty中迭代数组时,我得到的结果与同一数组的print_r()冲突。

在数组上执行print_r()时,我可以看到数组中有2个对象,每个对象都是唯一的。但是,当我在数组的每个项目上运行print_r()时(通过foreach循环),我似乎得到了每个项目相同的结果。

任何人都可以确定我做错了吗?

请参阅以下代码示例和结果。

代码:

{$fields.rgggo_spreadsheetcellmap_documents.value->beans|@print_r} 

输出继电器:

Array
(
    [a852b076-a5cb-dda9-3868-52010d6957ab] => RGGGO_SpreadsheetCellMap Object
        (
            [new_schema] => 1
            [module_dir] => RGGGO_SpreadsheetCellMap
            [object_name] => RGGGO_SpreadsheetCellMap
            [table_name] => rgggo_spreadsheetcellmap
            [importable] => 
            [id] => a852b076-a5cb-dda9-3868-52010d6957ab
            [name] => 
            [date_entered] => 08/06/2013 09:52am
            [date_modified] => 08/06/2013 02:16pm
            [modified_user_id] => 1
            [modified_by_name] => Sean
            [created_by] => 1
            [created_by_name] => Sean
            [description] => Test 2
            [deleted] => 0
            [created_by_link] => 
            [modified_user_link] => 
            [team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
            [team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
            [team_count] => 
            [team_name] => Development
            [team_link] => 
            [team_count_link] => 
            [teams] => 
            [assigned_user_id] => 
            [assigned_user_name] => 
            [assigned_user_link] => 
            [field] => document_type_text_c
            [row] => 3
            [col] => 1

            .... a bunch more stuff here
        )

    [f038918d-a13d-69f0-3541-51fff82f0497] => RGGGO_SpreadsheetCellMap Object
        (
            [new_schema] => 1
            [module_dir] => RGGGO_SpreadsheetCellMap
            [object_name] => RGGGO_SpreadsheetCellMap
            [table_name] => rgggo_spreadsheetcellmap
            [importable] => 
            [id] => f038918d-a13d-69f0-3541-51fff82f0497
            [name] => 
            [date_entered] => 08/05/2013 02:10pm
            [date_modified] => 08/06/2013 02:17pm
            [modified_user_id] => 1
            [modified_by_name] => Sean
            [created_by] => 1
            [created_by_name] => Sean
            [description] => 
            [deleted] => 0
            [created_by_link] => 
            [modified_user_link] => 
            [team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
            [team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
            [team_count] => 
            [team_name] => Development
            [team_link] => 
            [team_count_link] => 
            [teams] => 
            [assigned_user_id] => 
            [assigned_user_name] => 
            [assigned_user_link] => 
            [field] => description
            [row] => 2
            [col] => 1

            .... a bunch more stuff here
        )
)

当我迭代数组时......

{{foreach from=$fields.rgggo_spreadsheetcellmap_documents.value->beans key=k item=v}}
    <pre>
    {$v|@print_r}
    </pre>
{{/foreach}}

我得到了这些结果:

RGGGO_SpreadsheetCellMap Object
(
    [new_schema] => 1
    [module_dir] => RGGGO_SpreadsheetCellMap
    [object_name] => RGGGO_SpreadsheetCellMap
    [table_name] => rgggo_spreadsheetcellmap
    [importable] => 
    [id] => f038918d-a13d-69f0-3541-51fff82f0497
    [name] => 
    [date_entered] => 08/05/2013 02:10pm
    [date_modified] => 08/06/2013 02:17pm
    [modified_user_id] => 1
    [modified_by_name] => Sean
    [created_by] => 1
    [created_by_name] => Sean
    [description] => 
    [deleted] => 0
    [created_by_link] => 
    [modified_user_link] => 
    [team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
    [team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
    [team_count] => 
    [team_name] => Development
    [team_link] => 
    [team_count_link] => 
    [teams] => 
    [assigned_user_id] => 
    [assigned_user_name] => 
    [assigned_user_link] => 
    [field] => description
    [row] => 2
    [col] => 1

    .... a bunch more stuff here
)

    RGGGO_SpreadsheetCellMap Object
(
    [new_schema] => 1
    [module_dir] => RGGGO_SpreadsheetCellMap
    [object_name] => RGGGO_SpreadsheetCellMap
    [table_name] => rgggo_spreadsheetcellmap
    [importable] => 
    [id] => f038918d-a13d-69f0-3541-51fff82f0497
    [name] => 
    [date_entered] => 08/05/2013 02:10pm
    [date_modified] => 08/06/2013 02:17pm
    [modified_user_id] => 1
    [modified_by_name] => Sean
    [created_by] => 1
    [created_by_name] => Sean
    [description] => 
    [deleted] => 0
    [created_by_link] => 
    [modified_user_link] => 
    [team_id] => 2e201ae4-fac9-8426-44c5-4f54f5830831
    [team_set_id] => 65bd59b2-b3ed-fb2b-6a85-4f8888229942
    [team_count] => 
    [team_name] => Development
    [team_link] => 
    [team_count_link] => 
    [teams] => 
    [assigned_user_id] => 
    [assigned_user_name] => 
    [assigned_user_link] => 
    [field] => description
    [row] => 2
    [col] => 1

    .... a bunch more stuff here
)

1 个答案:

答案 0 :(得分:0)

我在另一个stackoverflow问题中找到了答案。问题是双重大括号和它们在SugarCRM中的使用。

Is there a difference between using a single vs. double brace (delimiters) in SugarCRM Smarty tpls command construct?