Symfony Controllers

From Littledamien Wiki
Revision as of 22:20, 27 January 2015 by Video8 (talk | contribs)
Jump to navigation Jump to search


Overview

A controller is a PHP callable you create that takes information from the HTTP request and constructs and returns an HTTP response (as a Symfony Response object).[1]

Requests, Controller, Response Lifecycle

Every request handled by a Symfony project goes through the same simple lifecycle. The framework takes care of all the repetitive stuff: you just need to write your custom code in the controller function:

  • Each request is handled by a single front controller file (e.g. app.php or app_dev.php) that bootstraps the application;
  • The Router reads information from the request (e.g. the URI), finds a route that matches that information, and reads the _controller parameter from the route;
  • The controller from the matched route is executed and the code inside the controller creates and returns a Response object;
  • The HTTP headers and content of the Response object are sent back to the client.[2]

Notes