The order of events in a Zend Framework 2 request
Which events fire, in what order, from loading modules to sending the response.
From the archive: first published on mohamedsharaf.net in October 2012. Rewritten and checked in 2026; some details may be out of date.
Zend Framework 2 is built around events, and knowing their order tells you where to hook your code. For a normal request:
1. Loading modules (ModuleManager)
loadModules- for each module:
loadModule.resolve, thenloadModule loadModules.post
2. Handling the request (MvcEvent)
bootstrap: set things up once per requestroute: match the URL to a controller and actiondispatch: run the controller action (dispatch.errorif routing or the controller fails)render: turn the view model into output (render.erroron failure)finish: last chance before the response is sent
Listening to dispatch with a high priority is the classic place for checks that must run before any controller, such as authentication.
Today: the same events exist in Laminas MVC, the continuation of Zend Framework.