Editing
Symfony Controllers
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
[[Category:Symfony]] [[Category:PHP]] [[Category:Web Development]] == 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).<ref>[http://symfony.com/doc/current/book/controller.html Symfony > Documentation > The Book > Controller]</ref> Typically, a controller is a method of a controller class:<ref>[http://symfony.com/doc/current/book/controller.html#a-simple-controller A Simple Controller], Symfony documentation</ref> <syntaxhighlight lang="php" highlight="6-7,9-10"> // src/AppBundle/Controller/HelloController.php namespace AppBundle\Controller; use Symfony\Component\HttpFoundation\Response; /** controller class... */ class HelloController { /** ...and the methods are the various "controllers" */ public function indexAction($name) { return new Response('<html><body>Hello '.$name.'!</body></html>'); } } </syntaxhighlight> == 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.<ref>[http://symfony.com/doc/current/book/controller.html#requests-controller-response-lifecycle Requests, Controller, Response Lifecycle], Symfony documentation</ref> == Notes == <references />
Summary:
Please note that all contributions to Littledamien Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Littledamien Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information