Created
April 30, 2021 13:27
-
-
Save garak/fbc48d46e5c6226fe0fe19597f5a5293 to your computer and use it in GitHub Desktop.
renderForm helper method for Symfony base controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
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)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With such method, you can just use
$this->renderForm('mytemplate.html.twig', $form)
.See https://symfony.com/blog/new-in-symfony-5-3-form-handler-helper