【问题标题】:Zend throw 404 headers in development modeZend 在开发模式下抛出 404 标头
【发布时间】:2013-04-25 14:30:15
【问题描述】:

所以我正在开发一个应用程序,我对控制器进行了一些 ajax 调用,如果没有数据会抛出 404。

throw new Zend_Controller_Action_Exception('This page does not exist', 404);

问题是我有$this->frontController->throwExceptions(true);所以在开发模式下会抛出一个错误,但它没有设置404标头,我需要标头,因为在基于标头的ajax调用中我知道接下来会发生什么。

有没有办法在 throwExceptions 设置为 true 的开发模式下抛出 404 标头?

【问题讨论】:

    标签: php jquery zend-framework


    【解决方案1】:

    您应该使用 ErrorHandler 插件并注册一个 ErrorController 来指示 404 页面,如下所述:

    http://framework.zend.com/manual/1.12/en/zend.controller.plugins.html#zend.controller.plugins.standard.errorhandler

    【讨论】:

      【解决方案2】:

      解决办法是拨打:->sendHeaders();

      $this->getResponse()-> setHttpResponseCode(405)-> setRawHeader('HTTP/1.1 405 Method Not Allowed')->sendHeaders();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-10-12
        • 2021-03-29
        • 2014-03-14
        • 1970-01-01
        • 2021-06-24
        • 2011-01-25
        • 1970-01-01
        相关资源
        最近更新 更多