ZF2: How to attach module specific listener for dispatch.error

可紊 提交于 2019-12-01 19:38:18

The reason it is working for dispatch but not dispatch.error is that the dispatch event gets triggered from within in the controller (see Zend\Mvc\Controller\AbstractController::dispatch)

Because you extend this class with your own namespaced controller, it is possible to associate the event with that namespace.

However, the dispatch.error event may be triggered before a controller (and with it the context of your namespace) is ever loaded. This happens according to more than one condition in Zend\Mvc\DispatchListener.

In order to customize the way dispatch.error is handled, you will likely need to write a custom listener for that event, or even write your own DispatchListener (though I'd recommend against that). You can then perhaps look at the routeMatch to figure out what you'd like to do next. If you're using the ModuleRouteListener this could be pretty easy.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!