In the shortest terms, routing is about linking the controllers with URLs entered in browser. Todays modern web applications need nice URLs. This means moving away from URLs like /index.php?product_id=23
to something like /catalog/product/t-shirt
. This is where routing comes in to play.
Symfony has a powerful routing mechanism that enables us to do the following:
Create complex routes which map to controllers
Generate URLs inside templates
Generate URLs inside controllers
Load routing resources from various locations
The way routing works in Symfony is that all of the requests come through app.php
. Then, the Symfony core asks the router to inspect the request. The router then matches the incoming URL to a specific route and returns information about the route. This information, among other things, includes the controller that should be executed. Finally, the Symfony kernel executes the controller, which returns a response object.
All of the application routes are loaded from a single routing...