Skip to content

Commit dbc77f5

Browse files
committed
minor symfony#11272 [Form] Add example for createNamed Form (wimme002)
This PR was squashed before being merged into the 3.4 branch (closes symfony#11272). Discussion ---------- [Form] Add example for createNamed Form The docs are not very clear where the FormFactory comes from and how to use this method <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/roadmap for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `master` for features of unreleased versions). --> Commits ------- 617621a [Form] Add example for createNamed Form
2 parents 6e0d97f + 617621a commit dbc77f5

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)