@@ -194,18 +194,48 @@ from a predefined list::
194
194
$colors,
195
195
0
196
196
);
197
- $output->writeln('You have just selected: ' . $colors[$color]);
197
+ $output->writeln('You have just selected: '. $colors[$color]);
198
198
199
199
// ... do something with the color
200
200
201
201
The option which should be selected by default is provided with the fourth
202
- parameter . The default is ``null ``, which means that no option is the default one.
202
+ argument . The default is ``null ``, which means that no option is the default one.
203
203
204
204
If the user enters an invalid string, an error message is shown and the user
205
205
is asked to provide the answer another time, until she enters a valid string
206
206
or the maximum attempts is reached (which you can define in the fifth
207
- parameter). The default value for the attempts is ``false ``, which means infinite
208
- attempts. You can define your own error message in the sixth parameter.
207
+ argument). The default value for the attempts is ``false ``, which means infinite
208
+ attempts. You can define your own error message in the sixth argument.
209
+
210
+ .. versionadded :: 2.3
211
+ Multiselect support was new in Symfony 2.3
212
+
213
+ Multiple Choices
214
+ ................
215
+
216
+ Sometimes, multiple answers can be given. The DialogHelper provides this
217
+ feature using comma seperated values. This is disabled by default, to enable
218
+ this set the seventh argument to ``true ``::
219
+
220
+ // ...
221
+
222
+ $selected = $dialog->select(
223
+ $output,
224
+ 'Please select your favorite color (default to red)',
225
+ $colors,
226
+ 0,
227
+ false,
228
+ 'Value "%s" is invalid',
229
+ true // enable multiselect
230
+ );
231
+
232
+ $selectedColors = array_map(funtion($c) use ($colors) {
233
+ return $colors[$c];
234
+ }, $selected)
235
+
236
+ $output->writeln('You have just selected: ' . implode(', ', $selectedColors));
237
+
238
+ Now, when the user inputted ``1,2 ``, the result will be: ``You have just selected: blue, yellow ``
209
239
210
240
Testing a Command which expects input
211
241
-------------------------------------
0 commit comments