|
4 | 4 | How to Embed a Collection of Forms
|
5 | 5 | ==================================
|
6 | 6 |
|
7 |
| -In this article, you'll learn how to create a form that embeds a collection |
8 |
| -of many other forms. This could be useful, for example, if you had a ``Task`` |
9 |
| -class and you wanted to edit/create/remove many ``Tag`` objects related to |
10 |
| -that Task, right inside the same form. |
| 7 | +Symfony Forms can embed a collection of many other forms, which is useful to |
| 8 | +edit related entities in a single form. In this article, you'll create a form to |
| 9 | +edit a ``Task`` class and, right inside the same form, you'll be able to edit, |
| 10 | +create and remove many ``Tag`` objects related to that Task. |
11 | 11 |
|
12 | 12 | Let's start by creating a ``Task`` entity::
|
13 | 13 |
|
@@ -45,13 +45,14 @@ Let's start by creating a ``Task`` entity::
|
45 | 45 |
|
46 | 46 | .. note::
|
47 | 47 |
|
48 |
| - The ``ArrayCollection`` is specific to Doctrine and is basically the |
49 |
| - same as using an ``array`` (but it must be an ``ArrayCollection`` if |
50 |
| - you're using Doctrine). |
| 48 | + The `ArrayCollection`_ is specific to Doctrine and is similar to a PHP array |
| 49 | + but provides many utility methods. |
51 | 50 |
|
52 | 51 | Now, create a ``Tag`` class. As you saw above, a ``Task`` can have many ``Tag``
|
53 | 52 | objects::
|
54 | 53 |
|
| 54 | +.. code-block:: php |
| 55 | +
|
55 | 56 | // src/Entity/Tag.php
|
56 | 57 | namespace App\Entity;
|
57 | 58 |
|
@@ -688,3 +689,4 @@ the relationship between the removed ``Tag`` and ``Task`` object.
|
688 | 689 | .. _`JSFiddle`: http://jsfiddle.net/847Kf/4/
|
689 | 690 | .. _`@a2lix/symfony-collection`: https://github.com/a2lix/symfony-collection
|
690 | 691 | .. _`symfony-collection`: https://github.com/ninsuo/symfony-collection
|
| 692 | +.. _`ArrayCollection`: https://www.doctrine-project.org/projects/doctrine-collections/en/1.6/index.html |
0 commit comments