在RainTPL中获取PHP数组

时间:2013-06-11 15:17:24

标签: php smarty

我想使用数组并使用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

1 个答案:

答案 0 :(得分:1)

你有一个2D数组,但你只循环外部数组。如果要显示第二级的键值对,则必须在循环(嵌套循环)中放置另一个循环,以访问内部数组中的键值对。

<div> 
    <ul>
        {loop="portalTopics"}
            {loop="value"}
                <li>{$key} = {$value}</li>
            {/loop}
        {/loop}
    </ul>
</div>