Zend Framework:如何删除控制器中呈现的视图?

问题描述:

我想使这些套的观点之一:Zend Framework:如何删除控制器中呈现的视图?

  1. 体佩$ ID1

OR

  1. 体佩$ id2

其设置exsists。

我不喜欢这样写道:

try { 
    $this->render("head"); 
    $this->render("body-$id1"); 
    $this->render("foot"); 
} catch (Exception $e) { 
    $this->render("head"); 
    $this->render("body-$id2"); 
    $this->render("foot"); 
} 

,但它会导致head观点被渲染两次,如果身体 - $ ID1不存在。

你有更好的解决方案吗?

在另一种说法中,我可以在渲染之前检查body-$id1的存在吗?

那么,它会在“try”块中运行任何有效的脚本,但是如果失败,它将呈现“catch”块中的所有内容。所以,你可能需要更多的东西一样:

$this->render("head"); 
try { 
    $this->render("body-$id1"); 
} catch (Exception $e) { 
    $this->render("body-$id2"); 
} 
$this->render("foot"); 

我没有看到检查的API函数如果视图存在,但你可以写一个控制器助手,只是获取路径到您的视图脚本,并使用file_exists到检查该路径中是否存在“body - {$ id1}”。