试图在zend中禁用布局

时间:2014-03-30 23:58:58

标签: zend-framework layout

我尝试以这种方式禁用zend动作中的布局:

$this->_helper->layout->disableLayout();

但它不起作用:

 Fatal error: Call to undefined method Application_Controller_Helper_Layout::disableLayout() in application/controllers/AssetController.php on line 18

我认为这是因为我自己做了帮助。

Bootsrap.php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initMyActionHelpers()
    {
        $this->bootstrap('frontController');
        $layout = Zend_Controller_Action_HelperBroker::getStaticHelper('Layout');
        Zend_Controller_Action_HelperBroker::addHelper($layout);
    }

}

的application.ini

resources.frontController.actionhelperpaths.Application_Controller_Helper = APPLICATION_PATH "/controllers/helpers"

和我的助手

class Application_Controller_Helper_Layout extends Zend_Controller_Action_Helper_Abstract
{
    public function preDispatch()
    {
    }
}

谢谢!

1 个答案:

答案 0 :(得分:1)

如果要重写Zend默认布局助手,请扩展Zend_Layout_Controller_Action_Helper_Layout。

class Application_Controller_Helper_Layout extends Zend_Layout_Controller_Action_Helper_Layout

如果你没有在你自己的助手中覆盖它,你仍然可以使用默认的disableLayout()函数。

尝试使用以下方法进行测试:

class Application_Controller_Helper_Layout extends Zend_Layout_Controller_Action_Helper_Layout
{
    public function preDispatch(){}

    public function disableLayout(){
        echo "I won't disable layout anymore, because I overwrote the action with displaying this string.";
    }
}