Skip to content

Commit 617621a

Browse files
wimme002wouterj
authored andcommitted
[Form] Add example for createNamed Form
1 parent d8e4b4d commit 617621a

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

forms.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,23 @@ 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+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
684+
685+
class DefaultController extends AbstractController
686+
{
687+
public function newAction()
688+
{
689+
$task = ...;
690+
$form = $this->get('form.factory')->createNamed('name', TaskType::class, $task);
691+
692+
// ...
693+
}
694+
}
695+
680696
You can even suppress the name completely by setting it to an empty string.
681697

682698
Final Thoughts

0 commit comments

Comments
 (0)