Tutorial by Examples

// src/AppBundle/Controller/HelloWorldController.php namespace AppBundle\Controller; use Symfony\Component\HttpFoundation\Response; class HelloWorldController { public function helloWorldAction() { return new Response( '<html><body>Hello World!<...
Most of the time, you will want to render HTML responses from a template instead of hard-coding the HTML in your controller. Also, your templates will not be static but will contain placeholders for application data. By default Symfony comes with Twig, a powerful templating language. In order to us...
Sometimes you want to return a 404 (Not Found) response, because the requested resource does not exist. Symfony allows you to do so by throwing a NotFoundHttpException. The Symfony base Controller exposes a createNotFoundException method which creates the exception for you: public function indexAc...
If you need to access the Request object (for instance to read the query parameters, to read an HTTP header or to process an uploaded file), you can receive the request as a method argument by adding a type-hinted argument: use Symfony\Component\HttpFoundation\Request; public function indexActio...

Page 1 of 1