Skip to content

Update Controller.tpl.php to use createView() method by default #1709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from

Conversation

DocFX
Copy link

@DocFX DocFX commented Jun 4, 2025

Hi, just stumble recurringly on this while using make:crud.

There are several ways to address that, like using render() or else, but I think the most concensual way of doing so would be to just add createView() to all Controller methods that pass forms to templates.

I might be wrong on that, though, but it's one of the first things I do in those files right after generating them.

@@ -45,7 +45,7 @@ public function new(Request $request, EntityManagerInterface $entityManager): Re

return $this->render('<?= $templates_path ?>/new.html.twig', [
'<?= $entity_twig_var_singular ?>' => $<?= $entity_var_singular ?>,
'form' => $form,
'form' => $form->createView(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

render() will automatically call createView() on all parameters that are an instance of FormInterface!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that it does... If not yet done. The question is: shouldn't this be done?

Pros: more explicit.
Cons: doesn't handle the 422 code, for instance (like Turbo doesn't like this).

I'm split on that. Hence the questioning! :)

@DocFX
Copy link
Author

DocFX commented Jun 4, 2025

Annnd... The test runner crashed :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants