在 Zend Framework MVC 下禁用 view 或者 layout

在 Zend_Controller 中禁用 view

在 Action 级别禁用 view:

 
<?php
class FooController extends Zend_Controller_Action
{
    public function barAction()
    {
         $this->_helper->viewRenderer->setNoRender();
    }
}
?>

在执行当前 action 的时候会不会展示 view .

在 Controller 级别禁用 view:

 
<?php
class FooController extends Zend_Controller_Action
{
    public function init()
    {
         $this->_helper->viewRenderer->setNoRender();
    }
}
?>

在执行当前 controller 下的所有 action 的时候都不会展示 view .

全局级别禁用 view:

 
<?php
Zend_Controller_Front::getInstance()->setParam('noViewRenderer', true);
?>

在整个程序的执行过程中都不会展示 view .

在 Controller 中禁用或改变 layout

禁用 layout

 
<?php
class FooController extends Zend_Controller_Action
{
    public function barAction()
    {
        $this->_helper->layout->disableLayout();
    }
}
?>

在此 action 执行的时候将不会使用 Zend_Layout 。

改变 layout

 
<?php
class FooController extends Zend_Controller_Action
{
    public function barAction()
    {
        $this->_helper->layout->setLayout('other');
    }
}
?>

在此 action 执行的时候将使用名为 other 的 layout 。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>