Screening Entry Level

How does routing work in Symfony? Explain how a URL gets matched to a controller action, and the different ways you can define routes.

Quick Tip

Cover the essentials: "I define routes with #[Route] attributes on controller methods. Parameters like {id} are passed as method arguments. I use route names everywhere so URLs can change without breaking links."

What good answers include

Symfony matches incoming URLs against a compiled list of route definitions. Routes map a URL pattern and HTTP method to a controller callable. Routes can be defined via PHP attributes (#[Route]), YAML, XML, or PHP configuration. Attributes on controller methods are the modern convention. Key features: route parameters ({slug}), requirements (regex constraints on parameters), defaults, route names for URL generation, and route prefixes on controller classes. The router is compiled and cached — route matching is fast even with hundreds of routes. Strong candidates mention: the debug:router command for listing all routes, generating URLs with the router service or Twig path()/url() functions, and that route priority follows definition order.

What interviewers are looking for

Fundamental Symfony skill. Candidates who cannot explain how a request reaches a controller will struggle with any Symfony project. Ask them to define a route with a parameter and explain how they would generate a link to it in a template.

← All Symfony questions