1

My error page never hits the following code during execution.

Understanding the DesignHandler is not important here but what is important is when an error occurs it routes correctly to the error page but never hits this piece of code.

namespace Application;

class Module
{
    public function onBootstrap(MvcEvent $e)
    {
        $events = $e->getApplication()->getEventManager();  
        $sharedEvents = $events->getSharedManager();
        $sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) { 
            $designHandler = Pluto::app()->getDesignHandler();
            $designHandler->pump($e);
        }, 20);
     }
}

OR ( I tried both onbootstrap and init)

namespace Application;

class Module
{
    public function init(\Zend\ModuleManager\ModuleManager $manager)
    {
        $events = $manager->getEventManager();  
        $sharedEvents = $events->getSharedManager();
        $sharedEvents->attach(__NAMESPACE__, 'dispatch', function($e) { 
            $designHandler = Pluto::app()->getDesignHandler();
            $designHandler->pump($e);
        }, 20);
     }
}

I have no clue as how to resolve this. I imagine that when an error hits it short circuits the route and this code never gets hit

UPDATE

I also tried this with both pieces of code and no success:

 $sharedEvents->attach(__NAMESPACE__, 'dispatch.error', function($e) {
        $designHandler = Pluto::app()->getDesignHandler();
        $designHandler->pump($e);
    }, 20);
somejkuser
  • 8,856
  • 20
  • 64
  • 130
  • whey say "it never hits this piece of code", are you referring to the `bootstrap` and `init` methods, or to the anonymous function you are trying to attach to `dispatch` and/or `dispatch.error`? and what kind of error are you triggering? Using `onDispatch` inside your controller isn't feasible? – yivi Dec 28 '16 at 16:18
  • i am not able to get to the code that is within the dispatch and dispatch.error events when the request has been rerouted to the error page/ – somejkuser Dec 28 '16 at 16:23
  • The anonymous function then. Ok. What about using `onDispatch` method on your controller? – yivi Dec 28 '16 at 16:24
  • Id prefer to handle this at a larger global level and i dont feel dealing with error routing should be done inside a controller right? – somejkuser Dec 28 '16 at 16:25
  • If the dispatch logic is specific to that controller, I don't see why not. From your first piece of code I thought you wanted to attach both to regular `dispatch` events and to `dispatch.error` anyway. – yivi Dec 28 '16 at 16:27
  • I dont understand why you would handle global level error handling inside a specific controller – somejkuser Dec 28 '16 at 16:30
  • Again, from your question is not clear that you are worried only about error events. Only that the problem appear on error events. You are trying to attach first to "dispatch" directly. – yivi Dec 28 '16 at 16:31
  • Tried rising the priority? I think that you may need a higher priority (100) for errors. – yivi Dec 28 '16 at 16:37
  • http://stackoverflow.com/questions/17948543/zf2-how-to-attach-module-specific-listener-for-dispatch-error – yivi Dec 28 '16 at 16:43

0 Answers0