所以我在一个应用程序上工作,我做了一些ajax调用控制器,在没有数据的情况下抛出404。
throw new Zend_Controller_Action_Exception('This page does not exist', 404);
问题是,我有$this->frontController->throwExceptions(true);
所以在开发模式抛出错误,但它不设置404标头,我需要标头,因为在基于标头的ajax调用中,我知道下一步是什么。
是否有办法抛出404头在开发模式与throwExceptions
设置为true
?
你应该使用ErrorHandler Plugin并注册一个ErrorController来指示404页面,如下所示:
http://framework.zend.com/manual/1.12/en/zend.controller.plugins.html zend.controller.plugins.standard.errorhandler
解决方法是调用:->sendHeaders();
$this->getResponse()-> setHttpResponseCode(405)-> setRawHeader('HTTP/1.1 405 Method Not Allowed')->sendHeaders();