我想使用数组并使用rainTpl获取,我可以为它分配数组,但我无法获取
PHP:
$portalTopics =array(
array('id' => 4,
'subject' => 1111111,
'description' => vvvvvvvvvvvvv,
'date_time' => '2013-05-26',
'posted_by' => 1,
'tags' => '',
'category' => 1,
't_status' => 1,
'post_type' => 1,
'can_comment' => 1,
'from_dateTime' =>' 0000-00-00 00:00:00',
'to_dateTime' => '0000-00-00 00:00:00',
'portal' => 0,
'thumb_image' => 'eNortjKwUlKyBlwwB0UBlw',
'order_display' => 9
),
array('id' => 5,
'subject' => 22222222222,
'description' => fffffffffffff,
'date_time' => '2013-05-26',
'posted_by' => 1,
'tags' => '',
'category' => 1,
't_status' => 1,
'post_type' => 1,
'can_comment' => 1,
'from_dateTime' =>' 0000-00-00 00:00:00',
'to_dateTime' => '0000-00-00 00:00:00',
'portal' => 0,
'thumb_image' => 'eNortjKwUlKyBlwwB0UBlw',
'order_display' => 9
)
);
$tpl->assign( $portalSettings );
$tpl->assign( 'portalTopics',$portalTopics );
echo $tpl->draw( 'main');
以下代码是fetch main.html
数组
portalTopics
文件
RainTPL:
<div>
<ul>
{loop="portalTopics"}
<li>{$key} = {$value}</li>
{/loop}
</ul>
</div>
结果:
0 = Array
1 = Array
答案 0 :(得分:1)
你有一个2D数组,但你只循环外部数组。如果要显示第二级的键值对,则必须在循环(嵌套循环)中放置另一个循环,以访问内部数组中的键值对。
<div>
<ul>
{loop="portalTopics"}
{loop="value"}
<li>{$key} = {$value}</li>
{/loop}
{/loop}
</ul>
</div>