default error controller never gets called
I am trying to use Zend_Controller_Plugin_ErrorHandler to handle all 404 and 500 errors. But so far, I don't even think my error controller is getting called at all. The index controller for me default module and another test module both work fine any way I call them in the URL. But I don't think my error controller ever gets called at all unless I specify it directly. For example, if I request /default/error/error, my error controller gets called and I see the error page I would expect. But if I go to /doesnotexist, then $frontController->dispatch () throws an "invalid controller specified" exception. The examples of how to do this all look very simple. I copied them, but it does not work. Here is what I am doing.
In my bootstrap:
$frontController = Zend_Controller_Front::getInstance ();
$frontController->setControllerDirectory (array (
"default" => $appDir."/default/controllers",
"professional" => $appDir."/module2/controllers"));
$frontController->setDefaultModule ("default");
$frontController->registerPlugin (new Zend_Controller_Plugin_ErrorHandler ());
$frontController->returnResponse (true);
$frontController->throwExceptions (true);
In /default/controllers/ErrorController.php:
(as far as I can tell, this controller never gets called when I request on invalid controller)
class ErrorController extends Zend_Controller_Action
{
protected $_view = null;
protected $_registry = null;
public function init ()
{
parent::init ();
$this->_helper->removeHelper ('viewRenderer');
$this->_view = $this->getInvokeArg ("view");
$this->_registry = Zend_Registry::getInstance ();
}
public function errorAction ()
{
$this->getResponse ()->setRawHeader ('HTTP/1.1 404 Not Found');
$this->_view->setScriptPath ($appDir."/default/views/scripts");
$this->getResponse ()->setBody ($this->_view->render ("error.phtml"));
// I never tested this because ZF never calls this function.
/*
$error = $this->_getParam ('error_handler');
switch ($error->type)
{
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ ACTION:
// 404 error -- controller or action not found
$this->getResponse ()->setRawHeader ('HTTP/1.1 404 Not Found');
$this->_view->setScriptPath ($this->_registry ['appDir']."/default/views/scripts");
$this->_response->setBody ($this->_view->render ("error.phtml"));
break;
default:
$this->getResponse ()->setRawHeader ('HTTP/1.1 404 Not Found');
$this->_view->setScriptPath ($this->_registry ['appDir']."/default/views/scripts");
$this->_response->setBody ($this->_view->render ("error.phtml"));
}
*/
}
public function __call ($name, $parameters)
{
$this->_redirect ('/');
}
}
|