ZF:禁用动作助手viewRenderer

时间:2012-05-21 09:52:25

标签: php ajax zend-framework

为了提供ajax操作,我执行以下操作:

    public function preDispatch()
    {
        if ($this->getRequest()->isXmlHttpRequest()) {
                Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer');
                Zend_Layout::getMvcInstance()->disableLayout();
        }           
    }

但是响应出现以下错误: 在路径中找不到脚本'async / tax.phtml'(/ var / www / app / trunc / application / views / scripts /:./ views / scripts /)

2 个答案:

答案 0 :(得分:0)

  1. 您是否检查了文件tax.phtml是否存在于/var/www/app/trunc/application/views/scripts/
  2. 如果存在,则在tax.phtml位置echo exit;位于文件底部。

答案 1 :(得分:0)

为什么不使用Ajaxcontext动作助手? http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.contextswitch

// supposedly in your async controller
public function init() {
$ajaxContext = $this->_helper->getHelper('AjaxContext');
$ajaxContext->addActionContext('tax', 'html')
}

然后将您的视图命名为“async / tax.ajax.phtml”,并确保您的ajax调用要求输入html格式。

通过这种方式,您甚至可以调整代码,使用相同的控制器/操作自动响应json,phtml或xml。

相关问题