Mohamed Sharaf

The order of events in a Zend Framework 2 request

Which events fire, in what order, from loading modules to sending the response.

· 1 min read

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)

  1. loadModules
  2. for each module: loadModule.resolve, then loadModule
  3. loadModules.post

2. Handling the request (MvcEvent)

  1. bootstrap: set things up once per request
  2. route: match the URL to a controller and action
  3. dispatch: run the controller action (dispatch.error if routing or the controller fails)
  4. render: turn the view model into output (render.error on failure)
  5. 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.

ShareWhatsAppLinkedInXTelegramFacebook