2013-04-26 118 views
0

我使用PEAR ITX添加模板。我的问题是,前2次($ number> 2)条件匹配,$ fileName2添加成功,块显示为预期;但是当第三次($ number == 2)条件匹配但$ fileName1看起来像加载失败时,它不显示任何东西。下面是我的示例代码:PHP Pear ITX添加和替换块文件

$template = new HTML_Template_ITX("./templates"); 
$template->loadTemplatefile($maintemplate,true,true); 

while($row = mysql_fetch_array($result)) 
{ 
    if($number==2) 
    { 
     $template->addBlockFile("CANDIDATES","CAN",$fileName1);| 
     $template->setCurrentBlock("CAN"); 
     //do anything i need 
    }else if($number>2) //first 2 times condition match, everything works well 
    { 
     $template->addBlockFile("CANDIDATES","CAN",$fileName2); 
     $template->setCurrentBlock("CAN"); 
     //do anything i need 
    } 

    $template->setCurrentBlock("MAIN"); 
$template->parseCurrentBlock(); 
} 

这种情况可能相反,如果第一次的2倍条件匹配($号== 2),然后第三次条件匹配($号> 2),但问题仍然是存在。

我发现的是replaceBlockfile(),我试过但不起作用。任何人都可以告诉我这是什么错误?谢谢。

回答

0

好像没人能回答我的问题,但我已经找出问题所在。 在我的问题中,每次循环使用相同的$模板,因为循环外的$ template。 我需要做的就是把:

$template = new HTML_Template_ITX("./templates"); 
$template->loadTemplatefile($maintemplate,true,true); 

while循环中,它的意思是每一次循环,可以创建一个“新”表。