Skip to content

Commit b83607e

Browse files
authored
Add example for createNamed Form
The docs are not very clear where the FormFactory comes from and how to use this method
1 parent b4fcfe4 commit b83607e

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
@@ -692,7 +692,19 @@ the choice is ultimately up to you.
692692

693693
The form name is automatically generated from the type class name. If you want
694694
to modify it, use the :method:`Symfony\\Component\\Form\\FormFactoryInterface::createNamed` method.
695-
You can even suppress the name completely by setting it to an empty string.
695+
You can even suppress the name completely by setting it to an empty string::
696+
697+
// src/Controller/TaskController.php
698+
use App\Form\TaskType;
699+
700+
public function new()
701+
{
702+
$task = ...;
703+
$form = $this->container->get('form.factory')->createNamed('customName', TaskType::class, $task);
704+
705+
// ...
706+
}
707+
696708

697709
Final Thoughts
698710
--------------

0 commit comments

Comments
 (0)