+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 17

Thread: default error controller never gets called

  1. #1
    bquade is offline Junior Member
    Join Date
    Jan 2008
    Posts
    4

    Thumbs up 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 ('/');
    }
    }

  2. #2
    zuhair is offline Junior Member
    Join Date
    Apr 2008
    Posts
    7

    Default Exactly

    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

  3. #3
    wudz is offline Junior Member
    Join Date
    May 2008
    Posts
    4

    Default

    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...

  4. #4
    freenity is offline Junior Member
    Join Date
    Apr 2008
    Posts
    8

    Default

    you should set throwExceptions to false, that should fix it.

  5. #5
    wudz is offline Junior Member
    Join Date
    May 2008
    Posts
    4

    Default

    I said it before ;-)

  6. #6
    zuhair is offline Junior Member
    Join Date
    Apr 2008
    Posts
    7

    Unhappy Not true

    Below is my front controller code from my bootstrapper

    $frontController = Zend_Controller_Front::getInstance();
    $frontController->throwExceptions(false);
    $frontController->setControllerDirectory('../../systems/admin/controllers');
    $router = $frontController->getRouter();
    $router->addRoute('app', new Zend_Controller_Router_Route('apps/:appname', array('controller' => 'apps', 'action' => 'index')));
    Zend_Layout::startMvc(array('layoutPath'=>'../../systems/admin/layouts'));
    $frontController->dispatch();

    I've tried a number of things but the best I could come up with was:
    $frontController->setParam('useDefaultControllerAlways', true);

  7. #7
    zuhair is offline Junior Member
    Join Date
    Apr 2008
    Posts
    7

    Thumbs down This sucks

    I installed Zend Studio with ZF 1.5 support and created new ZF project with it which generated index and error controllers and error controller does not get called their either.

    No person I know of has been successful in getting error controller to work!

  8. #8
    zuhair is offline Junior Member
    Join Date
    Apr 2008
    Posts
    7

    Exclamation Guys?

    Any ideas?

  9. #9
    zuhair is offline Junior Member
    Join Date
    Apr 2008
    Posts
    7

    Default Any clues

    Any clues?

  10. #10
    zuhair is offline Junior Member
    Join Date
    Apr 2008
    Posts
    7

    Default Why?

    Why???

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Action helper (redirector) loading error being called in a init method
    By radarve in forum Model-View-Controller (MVC)
    Replies: 2
    Last Post: 02-25-2010, 12:16 PM
  2. Replies: 1
    Last Post: 01-12-2010, 07:26 AM
  3. setting default controller to something different than index
    By matches in forum Model-View-Controller (MVC)
    Replies: 11
    Last Post: 08-21-2009, 11:00 AM
  4. Making index the default controller
    By americanu197 in forum Model-View-Controller (MVC)
    Replies: 3
    Last Post: 04-16-2008, 12:57 PM
  5. Replies: 0
    Last Post: 01-18-2008, 09:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts