Smarty无法看到我的变量

时间:2011-09-09 06:46:02

标签: php smarty

我使用smarty的自定义CMS有问题。它使用此代码显示新闻:

{foreach from=$news_anns key=key item=name}
            <div class="line" style="width:450px">
                <div class="date"><strong class="blue">{$name.dt_day}</strong><br />
                    {$name.mon}</div>
                <div class="right"><strong class="blue">{$name.title}</strong><br />
                <a href="/news/one/{$name.part_id}/{$name.id}/">more</a></div>
            </div>
{/foreach} 

并像这样查询:

function main_news_anns(){
global $db;
global $smarty;
$list = $db->select("SELECT n.id,n.title,DATE_FORMAT(n.dt,'%m') as dt_mon,DATE_FORMAT(n.dt,'%e') as dt_day, nt.id as part_id from cms_news n JOIN cms_news_tree nt ON n.pid=nt.id WHERE n.view_main=1 ORDER by n.dt DESC");
foreach ($list as $i=>$v){
$list[$i]['title'] = stripslashes($v['title']);
$list[$i]['mon'] = $this->ru_month[intval($v['dt_mon'])];
}
$smarty->assign(array("news_anns"=>$list));
}//ENDF

我需要添加更多显示新闻的变体。我在php lib中添加新代码:

function main_news_acts(){
global $db;
global $smarty;
$list = $db->select("SELECT n.id,n.title,DATE_FORMAT(n.dt,'%m') as dt_mon,DATE_FORMAT(n.dt,'%e') as dt_day, nt.id as part_id from cms_news n JOIN cms_news_tree nt ON n.pid=nt.id WHERE n.view_main=1 AND n.pid=4 ORDER by n.dt DESC");
foreach ($list as $i=>$v){
$list[$i]['title'] = stripslashes($v['title']);
$list[$i]['mon'] = $this->ru_month[intval($v['dt_mon'])];
}
$smarty->assign(array("news_acts"=>$list));
}//ENDF

并在html中:

{foreach from=$news_acts key=key item=act}
            <div class="line" style="width:450px">
                <div class="date"><strong class="blue">{$act.dt_day}</strong><br />
                    {$act.mon}</div>
                <div class="right"><strong class="blue">{$act.title}</strong><br />
                <a href="/news/one/{$act.part_id}/{$act.id}/">more</a></div>
            </div>
{/foreach}

没有显示! Smarty没有看到任何新添加的变量。然而,当我重命名$news_anns时 - 它是有效的。可能是什么问题?

0 个答案:

没有答案