Zend Framework: How to intentionally throw a 404 error?

Andrew picture Andrew · Nov 15, 2010 · Viewed 17.4k times · Source

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

Answer

Wouter Dorgelo picture Wouter Dorgelo · Nov 15, 2010

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);