Zend Framework: How to intentionally throw a 404 e

2019-03-09 18:09发布

I would like to intentionally cause a 404 error within one of the controllers in my Zend Framework application. How can I do this?

2条回答
干净又极端
2楼-- · 2019-03-09 18:31

You can always set the response code manually, without throwing any exceptions.

$this->_response->clearBody();
$this->_response->clearHeaders();
$this->_response->setHttpResponseCode(404);
查看更多
姐就是有狂的资本
3楼-- · 2019-03-09 18:32

A redirect to a 404 would be:

throw new Zend_Controller_Action_Exception('Your message here', 404);

Or without Exception:

$this->_response->clearBody();
$this->_response->clearHeaders();
$this->_response->setHttpResponseCode(404);
查看更多
登录 后发表回答