Skip to content

Commit 447a4c3

Browse files
committed
Add example for createNamed Form
The docs are not very clear where the FormFactory comes from and how to use this method
1 parent d8e4b4d commit 447a4c3

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

forms.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,19 @@ choice is ultimately up to you.
676676
.. note::
677677

678678
The form name is automatically generated from the type class name. If you want
679-
to modify it, use the :method:`Symfony\\Component\\Form\\FormFactoryInterface::createNamed` method.
679+
to modify it, use the :method:`Symfony\\Component\\Form\\FormFactoryInterface::createNamed` method::
680+
681+
// src/AppBundle/Controller/DefaultController.php
682+
use AppBundle\Form\TaskType;
683+
684+
public function newAction()
685+
{
686+
$task = ...;
687+
$form = $this->container->get('form.factory')->createNamed('name', TaskType::class, $task);
688+
689+
// ...
690+
}
691+
680692
You can even suppress the name completely by setting it to an empty string.
681693

682694
Final Thoughts

0 commit comments

Comments
 (0)