Skip to content

Instantly share code, notes, and snippets.

Created Apr 30, 2021
What would you like to do?
renderForm helper method for Symfony base controller
protected function renderForm(string $template, FormInterface $form, array $params = []): Response
$code = $form->isSubmitted() && !$form->isValid() ? Response::HTTP_UNPROCESSABLE_ENTITY : Response::HTTP_OK;
return $this->render($template, array_merge($params, ['form' => $form->createView()]), new Response(null, $code));
Copy link

garak commented Apr 30, 2021

With such method, you can just use $this->renderForm('mytemplate.html.twig', $form).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment