|
|||
|
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 ('/'); } } |
|
|||
|
Exactly, I've been struggling with the same problem for ages and guess what no one gives two shits about the issue!
![]() I've tried almost every single trick in the book (manual) and various forum tips but nothing seems to work. One thought was that this could be because I am not using a modular directory structure, so I created a module called 'default'. But that too obviously did not work ![]() Quiety frankly dude.. am over it ![]() |
|
|||
|
try to change "throwExeptions" in your bootstrap:
$frontController->throwExceptions ( false ); I also don't have modular directory structure (like -> zuhair) I removed also: $frontController->setParam ( 'useDefaultControllerAlways', true ); in my case it's working when I call: http://.../no_existing_controller/ and http://.../no_existing_controller/no_existing_action/ but when I hit http://.../existing_controller/no_existing_action nothing is happening, and I dunno why... |
![]() |
| Thread Tools | |
| Display Modes | |
|
|