Tutorial by Examples

404 responses are returned when a resource is not found on the server, in Symfony this status can be created by throwing a NotFoundHttpException exception. To avoid an extra use statement inside a controller use the createNotFoundException() provided by the Controller class <?php namespace Bu...
In Symfony it's possible to define multiple routes for one action. This can be very helpful if you have functions that do the same but have different parameters. class TestController extends Controller { /** * @Route("/test1/{id}", name="test") * @Route("/...
When you are in a controllerAction And have a POST request coming in, but want to redirect it, to a different route, while still maintaining the POST method and the request object, you can use the following: return $this->redirectToRoute('route', array( 'request' => $request, ), 307); ...
Subdomain-based routing can be handled in Symfony using host parameter. For example, _locale parameter can be used as subdomain value. Assuming locale: en domain: somedomain.com parameters are defined in parameters.yml config file, route would be: /** * @Route( * "/", * ...
profile_user_profile: path: /profile/{id} defaults: { _controller: ProfileBundle:Profile:profile } requirements: id: \d+ methods: [get, delete] If you decide to use Routing.yml instead of Annotations You can get better view of all routes and...

Page 1 of 1