我使用PEAR ITX添加模板。我的问题是,前2次($number>2)条件匹配和$fileName2添加成功,块显示如预期;但是当第三次($number==2)条件匹配但$fileName1似乎加载失败时,它不显示任何东西。下面是我的示例代码:
$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次条件匹配($number==2),那么第三次条件匹配($number>2)但问题仍然存在。
我发现的是replaceBlockfile(),我试过但不起作用。谁能告诉我出了什么问题?谢谢你。
似乎没有人能回答我的问题,但我已经找出了问题所在。在我的问题中,每个times循环都使用相同的$template,因为$template在循环之外。我需要做的是把:
$template = new HTML_Template_ITX("./templates");
$template->loadTemplatefile($maintemplate,true,true);
在while循环中,意味着每次循环都会创建一个"NEW"表