From 617621a37fc538627021fe949b78d6325bc8c589 Mon Sep 17 00:00:00 2001 From: Wim Molenberghs Date: Tue, 2 Apr 2019 14:12:47 +0200 Subject: [PATCH] [Form] Add example for createNamed Form --- forms.rst | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/forms.rst b/forms.rst index e9b0e87acc7..fca24502693 100644 --- a/forms.rst +++ b/forms.rst @@ -676,7 +676,23 @@ choice is ultimately up to you. .. note:: The form name is automatically generated from the type class name. If you want - to modify it, use the :method:`Symfony\\Component\\Form\\FormFactoryInterface::createNamed` method. + to modify it, use the :method:`Symfony\\Component\\Form\\FormFactoryInterface::createNamed` method:: + + // src/AppBundle/Controller/DefaultController.php + use AppBundle\Form\TaskType; + use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; + + class DefaultController extends AbstractController + { + public function newAction() + { + $task = ...; + $form = $this->get('form.factory')->createNamed('name', TaskType::class, $task); + + // ... + } + } + You can even suppress the name completely by setting it to an empty string. Final Thoughts