Screening Entry Level

What is the role of a controller in Symfony? How do you access request data, return responses, and redirect the user?

Quick Tip

Keep it practical: "The controller takes a Request, calls a service for business logic, and returns a Response. I use $this->render() for HTML, $this->json() for APIs, and $this->redirectToRoute() after form submissions."

What good answers include

Controllers are callables (typically methods on classes extending AbstractController) that receive a Request and return a Response. Access request data via the Request object: $request->query->get() for GET parameters, $request->request->get() for POST data, $request->attributes->get() for route parameters. Return responses: return new Response() for raw content, $this->render() for Twig templates, $this->json() for JSON, $this->redirectToRoute() for redirects. AbstractController provides shortcut methods for rendering, redirecting, generating URLs, creating forms, and accessing the service container. Strong candidates mention: that controllers should be thin — business logic belongs in services, type-hinted action parameters for automatic argument resolution, and returning proper HTTP status codes.

What interviewers are looking for

Entry-level Symfony question. Candidates who cannot explain the request-response cycle in a controller need more framework experience. Those who mention keeping controllers thin and delegating to services show good architecture instincts even at a junior level.

← All Symfony questions