From 93618ed73e1274d4ac01d99bbcc5b57393bcc564 Mon Sep 17 00:00:00 2001 From: Varun Agrawal Date: Wed, 30 Mar 2016 16:55:40 +0530 Subject: [PATCH 1/3] Fixed a typo in configuration-block It is not rendered properly right now (https://symfony.com/doc/current/book/controller.html#route-parameters-as-controller-arguments) I think this should fix it --- book/controller.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/controller.rst b/book/controller.rst index 71e8c88b69c..a837c145aa5 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -260,7 +260,7 @@ to ``$name``. Just make sure they the name of the placeholder is the same as the name of the argument variable. Take the following more-interesting example, where the controller has two -arguments:: +arguments: .. configuration-block:: From f483209a8be72e41a713b0787543a9ede5ec3e7a Mon Sep 17 00:00:00 2001 From: RickieL Date: Tue, 29 Mar 2016 17:02:02 +0800 Subject: [PATCH 2/3] fixed a typo fixed a typo --- book/controller.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/book/controller.rst b/book/controller.rst index a837c145aa5..22a07737648 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -704,7 +704,7 @@ The Request and Response Object ------------------------------- As mentioned :ref:`earlier `, the framework will -pass the ``Request`` object to any controller argument taht is type-hinted with +pass the ``Request`` object to any controller argument that is type-hinted with the ``Request`` class:: use Symfony\Component\HttpFoundation\Request; From 37c7ce5227d87a70b52255624af49330eb1a558a Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Sat, 2 Apr 2016 20:10:06 +0200 Subject: [PATCH 3/3] Tests: Explain how to add or remove data in a collection of forms --- book/testing.rst | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/book/testing.rst b/book/testing.rst index 5d088e7345a..bda2ede4ef8 100644 --- a/book/testing.rst +++ b/book/testing.rst @@ -699,6 +699,48 @@ their type:: PHP format (it converts the keys with square brackets notation - e.g. ``my_form[subject]`` - to PHP arrays). +If you use a :doc:`Collection of Forms `, +you can't add fields to an existing form with +``$form['task[tags][0][name]'] = 'foo';``, this results in an error +``Unreachable field "…"`` because ``$form`` can only be used in order to +set values of existing fields. In order to add new fields, you have to +add the values to the raw data array:: + + // Get the form. + $form = $crawler->filter('button')->form(); + + // Get the raw values. + $values = $form->getPhpValues(); + + // Add fields to the raw values. + $values['task']['tag'][0]['name'] = 'foo'; + $values['task']['tag'][1]['name'] = 'bar'; + + // Submit the form with the existing and new values. + $crawler = $this->client->request($form->getMethod(), $form->getUri(), $values, + $form->getPhpFiles()); + + // The tag has been added to the collection. + $this->assertEquals(2, $crawler->filter('ul.tags > li')->count()); + +Where ``task[tags][0][name]`` is the name of a field created +with Javascript. + +You can remove an existing field, e.g. a tag:: + + // Get the values of the form. + $values = $form->getPhpValues(); + + // Remove the first tag. + unset($values['task']['tags'][0]); + + // Submit the data. + $crawler = $client->request($form->getMethod(), $form->getUri(), + $values, $form->getPhpFiles()); + + // The tag has been removed. + $this->assertEquals(0, $crawler->filter('ul.tags > li')->count()); + .. index:: pair: Tests; Configuration