@@ -12,11 +12,11 @@ objects from the database.
12
12
+-------------+------------------------------------------------------------------+
13
13
| Rendered as | can be various tags (see :ref: `forms-reference-choice-tags `) |
14
14
+-------------+------------------------------------------------------------------+
15
- | Options | - `class `_ |
15
+ | Options | - `choice_label `_ |
16
+ | | - `class `_ |
16
17
| | - `data_class `_ |
17
18
| | - `em `_ |
18
19
| | - `group_by `_ |
19
- | | - `property `_ |
20
20
| | - `query_builder `_ |
21
21
+-------------+------------------------------------------------------------------+
22
22
| Overridden | - `choice_list `_ |
@@ -55,13 +55,13 @@ be listed inside the choice field::
55
55
56
56
$builder->add('users', 'entity', array(
57
57
'class' => 'AcmeHelloBundle:User',
58
- 'property ' => 'username',
58
+ 'choice_label ' => 'username',
59
59
));
60
60
61
61
In this case, all ``User `` objects will be loaded from the database and
62
62
rendered as either a ``select `` tag, a set or radio buttons or a series
63
63
of checkboxes (this depends on the ``multiple `` and ``expanded `` values).
64
- If the entity object does not have a ``__toString() `` method the ``property ``
64
+ If the entity object does not have a ``__toString() `` method the ``choice_label ``
65
65
option is needed.
66
66
67
67
Using a Custom Query for the Entities
@@ -103,6 +103,29 @@ then you can supply the ``choices`` option directly::
103
103
Field Options
104
104
-------------
105
105
106
+ choice_label
107
+ ~~~~~~~~~~~~
108
+
109
+ **type **: ``string ``
110
+
111
+ This is the property that should be used for displaying the entities
112
+ as text in the HTML element. If left blank, the entity object will be
113
+ cast into a string and so must have a ``__toString() `` method.
114
+
115
+ .. note ::
116
+
117
+ The ``choice_label `` option is the property path used to display the option.
118
+ So you can use anything supported by the
119
+ :doc: `PropertyAccessor component </components/property_access/introduction >`
120
+
121
+ For example, if the translations property is actually an associative
122
+ array of objects, each with a name property, then you could do this::
123
+
124
+ $builder->add('gender', 'entity', array(
125
+ 'class' => 'MyBundle:Gender',
126
+ 'choice_label' => 'translations[en].name',
127
+ ));
128
+
106
129
class
107
130
~~~~~
108
131
@@ -133,29 +156,6 @@ and does so by adding ``optgroup`` elements around options. Choices that
133
156
do not return a value for this property path are rendered directly under
134
157
the select tag, without a surrounding optgroup.
135
158
136
- property
137
- ~~~~~~~~
138
-
139
- **type **: ``string ``
140
-
141
- This is the property that should be used for displaying the entities
142
- as text in the HTML element. If left blank, the entity object will be
143
- cast into a string and so must have a ``__toString() `` method.
144
-
145
- .. note ::
146
-
147
- The ``property `` option is the property path used to display the option.
148
- So you can use anything supported by the
149
- :doc: `PropertyAccessor component </components/property_access/introduction >`
150
-
151
- For example, if the translations property is actually an associative
152
- array of objects, each with a name property, then you could do this::
153
-
154
- $builder->add('gender', 'entity', array(
155
- 'class' => 'MyBundle:Gender',
156
- 'property' => 'translations[en].name',
157
- ));
158
-
159
159
query_builder
160
160
~~~~~~~~~~~~~
161
161
0 commit comments