I am trying to use the ErrorHandler plugin go manage all my 404 errors, as in
modules, controllers, and actions that are not found.

This is the code in my bootstrap index.php file:

require 'Zend/Controller/Front.php';
$front = Zend_Controller_Front::getInstance();
$front->registerPlugin(new Zend_Controller_Plugin_ErrorHandler());
$front->setControllerDirectory(SOURCE_PATH . 'Controllers');

$front->setModuleControllerDirectoryName('controllers');
$front->addModuleDirectory(SOURCE_PATH . 'Modules');

$front->setParam('noViewRenderer', true);
$front->setParam('disableOutputBuffering', true);

$front->dispatch();


I have an ErrorController.php file setup in my default controllers
directory, it's just the code from the docs demo:

<?php
class ErrorController extends Zend_Controller_Action
{
    public function errorAction()
    {
        $errors = $this->_getParam('error_handler');

        switch ($errors->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');

                $content =<<<EOH
<h1>Error!</h1>
<p>The page you requested was not found.</p>
EOH;
                break;
            default:
                // application error
                $content =<<<EOH
<h1>Error!</h1>
<p>An unexpected error occurred with your request. Please try again
later.</p>
EOH;
                break;
        }

        // Clear previous content
        $this->getResponse()->clearBody();

        $this->view->content = $content;
    }
}





If I try to access a non-existant module/class/action, instead of the
ErrorController being loaded, I get:
Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message
'Invalid controller specified...'

Just as a test, I can access the error controller directly by going to
site.com/error/error...

What have I done wrong here? I followed the code as it was done in the
documentation and it's just not working. All of my existing controllers work
fine, I just need to have a 404 handler.

If I can get this working, is there anything I could do to have the
ErrorController outside of the controllers directory? So that it can't be
directly accessed by going site.com/error/error?
-- 
View this message in context: 
http://www.nabble.com/Can%27t-get-ErrorHandler-plugin-to-work-as-a-404-handler-tf4694950s16154.html#a13420230
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to