在 SMARTY 模板中引用数组中的索引
我有一个 Smarty 中的数组变量,我正在尝试找出如何检索该信息。该变量称为 $COMMENTS,我执行了 $COMMENTS|@print_r
,这就是我得到的:
Array (
[0] => ModComments_CommentsModel Object (
[data:private] => Array (
[0] => 11686
[crmid] => 11686
[1] => 1679
[smcreatorid] => 1679
[2] => 1679
[smownerid] => 1679
[3] => 0
[modifiedby] => 0
[4] => ModComments
[setype] => ModComments
[5] =>
[description] =>
[6] => 2011-06-08 15:00:31
[createdtime] => 2011-06-08 15:00:31
[7] => 2011-06-08 15:00:31
[modifiedtime] => 2011-06-08 15:00:31
[8] => 2011-06-29 12:00:23
[viewedtime] => 2011-06-29 12:00:23
[9] =>
[status] =>
[10] => 0
[version] => 0
[11] => 1
[presence] => 1
[12] => 0
[deleted] => 0
[13] => 11686
[modcommentsid] => 11686
[14] => aasd
[commentcontent] => aasd
[15] => 6730
[related_to] => 6730
[16] =>
[parent_comments] =>
[17] => 11686
)
)
[1] => ModComments_CommentsModel Object (
[data:private] => Array (
[0] => 11685
[crmid] => 11685
[1] => 1679
[smcreatorid] => 1679
[2] => 1679
[smownerid] => 1679
[3] => 0
[modifiedby] => 0
[4] => ModComments
[setype] => ModComments
[5] =>
[description] =>
[6] => 2011-06-08 14:58:42
[createdtime] => 2011-06-08 14:58:42
[7] => 2011-06-08 14:58:42
[modifiedtime] => 2011-06-08 14:58:42
[8] =>
[viewedtime] =>
[9] =>
[status] =>
[10] => 0
[version] => 0
[11] => 1
[presence] => 1
[12] => 0
[deleted] => 0
[13] => 11685
[modcommentsid] => 11685
[14] => comment
[commentcontent] => comment
[15] => 6730
[related_to] => 6730
[16] =>
[parent_comments] =>
[17] => 11685
)
)
[2] => ModComments_CommentsModel Object (
[data:private] => Array (
[0] => 6731
[crmid] => 6731
[1] => 1679
[smcreatorid] => 1679
[2] => 1679
[smownerid] => 1679
[3] => 0
[modifiedby] => 0
[4] => ModComments
[setype] => ModComments
[5] =>
[description] =>
[6] => 2010-11-02 10:15:06
[createdtime] => 2010-11-02 10:15:06
[7] => 2010-11-02 10:15:06
[modifiedtime] => 2010-11-02 10:15:06
[8] =>
[viewedtime] =>
[9] =>
[status] =>
[10] => 0
[version] => 0
[11] => 1
[presence] => 1
[12] => 0
[deleted] => 0
[13] => 6731
[modcommentsid] => 6731
[14] => Test comment
[commentcontent] => Test comment
[15] => 6730
[related_to] => 6730
[16] =>
[parent_comments] =>
[17] => 6731
)
)
)
我正在尝试从中检索 11686 数字。有什么帮助吗?我尝试过 $COMMENTS[0][data:private][0]
但没有成功。
非常感谢任何帮助:)
I have a variable that is an array in Smarty, and I am trying to figure out how to retrieve that information. The variable is called $COMMENTS and I did $COMMENTS|@print_r
and this is what I got:
Array (
[0] => ModComments_CommentsModel Object (
[data:private] => Array (
[0] => 11686
[crmid] => 11686
[1] => 1679
[smcreatorid] => 1679
[2] => 1679
[smownerid] => 1679
[3] => 0
[modifiedby] => 0
[4] => ModComments
[setype] => ModComments
[5] =>
[description] =>
[6] => 2011-06-08 15:00:31
[createdtime] => 2011-06-08 15:00:31
[7] => 2011-06-08 15:00:31
[modifiedtime] => 2011-06-08 15:00:31
[8] => 2011-06-29 12:00:23
[viewedtime] => 2011-06-29 12:00:23
[9] =>
[status] =>
[10] => 0
[version] => 0
[11] => 1
[presence] => 1
[12] => 0
[deleted] => 0
[13] => 11686
[modcommentsid] => 11686
[14] => aasd
[commentcontent] => aasd
[15] => 6730
[related_to] => 6730
[16] =>
[parent_comments] =>
[17] => 11686
)
)
[1] => ModComments_CommentsModel Object (
[data:private] => Array (
[0] => 11685
[crmid] => 11685
[1] => 1679
[smcreatorid] => 1679
[2] => 1679
[smownerid] => 1679
[3] => 0
[modifiedby] => 0
[4] => ModComments
[setype] => ModComments
[5] =>
[description] =>
[6] => 2011-06-08 14:58:42
[createdtime] => 2011-06-08 14:58:42
[7] => 2011-06-08 14:58:42
[modifiedtime] => 2011-06-08 14:58:42
[8] =>
[viewedtime] =>
[9] =>
[status] =>
[10] => 0
[version] => 0
[11] => 1
[presence] => 1
[12] => 0
[deleted] => 0
[13] => 11685
[modcommentsid] => 11685
[14] => comment
[commentcontent] => comment
[15] => 6730
[related_to] => 6730
[16] =>
[parent_comments] =>
[17] => 11685
)
)
[2] => ModComments_CommentsModel Object (
[data:private] => Array (
[0] => 6731
[crmid] => 6731
[1] => 1679
[smcreatorid] => 1679
[2] => 1679
[smownerid] => 1679
[3] => 0
[modifiedby] => 0
[4] => ModComments
[setype] => ModComments
[5] =>
[description] =>
[6] => 2010-11-02 10:15:06
[createdtime] => 2010-11-02 10:15:06
[7] => 2010-11-02 10:15:06
[modifiedtime] => 2010-11-02 10:15:06
[8] =>
[viewedtime] =>
[9] =>
[status] =>
[10] => 0
[version] => 0
[11] => 1
[presence] => 1
[12] => 0
[deleted] => 0
[13] => 6731
[modcommentsid] => 6731
[14] => Test comment
[commentcontent] => Test comment
[15] => 6730
[related_to] => 6730
[16] =>
[parent_comments] =>
[17] => 6731
)
)
)
I am trying to retrieve the 11686 number from that. Any help? I have tried $COMMENTS[0][data:private][0]
but that didn't work.
Any help greatly appreciated :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,将
print_r()
输出放入您正在尝试访问数组中的第一个对象
$COMMENTS[0]
。由于它是对象,并且您的data
属性是私有的,因此您无法在 Smarty 中访问它。您必须编辑 ModComments_CommentsModel 类才能访问该属性的data
属性或crmid
键。例子:
First, put
print_r()
output into<pre>
tags so it is readable.You're trying to access the first object in your array,
$COMMENTS[0]
. Since that it is object, and yourdata
property is private, you cannot access it in Smarty. You would have to edit the ModComments_CommentsModel class to give you access to either thedata
property or thecrmid
key of the property.Example: