The MvcEventΒΆ

The ZF2 MVC layer incorporates and utilizes a custom Zend\EventManager\EventDescription type, Zend\Mvc\MvcEvent. This event is created during Zend\Mvc\Application::run(), and is passed directly to all events that method triggers. Additionally, if you mark your controllers with the Zend\Mvc\InjectApplicationEvent interface, it will be injected into those controllers.

The MvcEvent adds accessors and mutators for the following:

  • Application object
  • Request object
  • Response object
  • Router object
  • RouteMatch object
  • “Result”, usually the result of dispatching a controller
  • ViewModel object, typically representing the layout view model

The methods it defines are:

  • setApplication($application)
  • getApplication()
  • setRequest($request)
  • getRequest()
  • setResponse($response)
  • getResponse()
  • setRouter($router)
  • getRouter()
  • setRouteMatch($routeMatch)
  • getRouteMatch()
  • setResult($result)
  • getResult()
  • setViewModel($viewModel)
  • getViewModel()

The Application, Request, Response, Router, and ViewModel are all injected during the bootstrap event. Following the route event, it will be injected also with the RouteMatch object encapsulating the results of routing.

Since this object is passed around throughout the MVC, it is a common location for retrieving the results of routing, the router, and the request and response objects. Additionally, we encourage setting the results of execution in the event, to allow event listeners to introspect them and utilize them within their execution. As an example, the results could be passed into a view renderer.

Project Versions

Previous topic

Routing

Next topic

Available Controllers

This Page

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Go to The MvcEvent on GitHub.
  2. Edit file contents using GitHub's text editor in your web browser
  3. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  4. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  5. Your changes are now queued for review under project's Pull requests tab on GitHub.