Symfony

Routing & Controllers

Route annotations, parameters, constraints, redirects, Request/Response, JSON responses

20 preguntas de entrevista·
Junior
1

Which PHP attribute should be used to define a route in a Symfony 7 controller?

Respuesta

The #[Route] attribute from the Symfony\Component\Routing\Attribute namespace is the recommended method for defining routes in Symfony 7. It replaces Doctrine annotations that required special comments. Native PHP attributes provide better IDE integration and compile-time validation.

2

How to define a dynamic route parameter in Symfony?

Respuesta

Route parameters are defined using curly braces in the route path, for example {id}. This parameter is then automatically injected as an argument to the controller method with the same name. This convention allows automatic binding between the URL and controller parameters.

3

Which Symfony object represents the incoming HTTP request?

Respuesta

The Request class from the Symfony\Component\HttpFoundation namespace encapsulates all HTTP request data: GET/POST parameters, cookies, headers, uploaded files. It can be automatically injected into controller methods thanks to Symfony's autowiring.

4

How to restrict a route to a specific HTTP method?

5

How to return a JSON response from a Symfony controller?

+17 preguntas de entrevista

Domina Symfony para tu próxima entrevista

Accede a todas las preguntas, flashcards, tests técnicos, ejercicios de code review y simuladores de entrevista.

Empieza gratis