如何使用Php代码获取foreach's变量


Smarty:How can Use Php code get the foreach's variable

我的代码:

 <!--    {foreach from=$goods_cat.cat_id item=rec_cat name=f1}-->
       <?php      
         **echo  $rec_cat[id]; // get nothing, why?**
        $smarty->assign('goods_cat_' . $rec_cat[id], assign_cat_goods($rec_cat[id], 4));
        $smarty ->assign('cat_goods_nf' , 'goods_cat_' . $rec_cat[id]);           
?>
     <!--{foreach from=$cat_goods_nf item=goods}-->
                  {$goods.url}
     <!--{/foreach}--> 
  <!--{/foreach}--> 

我需要rec_cat的id,所以我使用PHP标签来获得它,但它的显示什么?为什么?我怎样才能改正呢?

不要在模板中使用<?php标签,而是使用Smarty的{php}标签:

http://www.smarty.net/docsv2/fr/language.function.php.tpl

然后得到变量如下:

$var = $this->get_template_vars('var');