Skip to content

Commit 3364c8a

Browse files
committed
Fixed a mistake in the docs about form creation
(you cannot simply call "->createForm()" in "any service that has access to the form factory")
1 parent 5b67852 commit 3364c8a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cookbook/form/dynamic_form_modification.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,16 +370,22 @@ it with :ref:`dic-tags-form-type`.
370370
If you wish to create it from within a controller or any other service that has
371371
access to the form factory, you then use::
372372

373-
class FriendMessageController extends Controller
373+
use Symfony\Component\DependencyInjection\ContainerAware;
374+
375+
class FriendMessageController extends ContainerAware
374376
{
375377
public function newAction(Request $request)
376378
{
377-
$form = $this->createForm('acme_friend_message');
379+
$form = $this->get('form.factory')->create('acme_friend_message');
378380

379381
// ...
380382
}
381383
}
382384

385+
If you extend the ``Symfony\Bundle\FrameworkBundle\Controller\Controller`` class, you can simply call::
386+
387+
$form = $this->createForm('acme_friend_message');
388+
383389
You can also easily embed the form type into another form::
384390

385391
// inside some other "form type" class

0 commit comments

Comments
 (0)