File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -155,6 +155,30 @@ will work:
155
155
app/console demo:greet Fabien --iterations=5 --yell
156
156
app/console demo:greet Fabien --yell --iterations=5
157
157
158
+ Asking the User for Information
159
+ -------------------------------
160
+
161
+ When creating commands, you have the ability to collect more information
162
+ from the user by asking him/her questions. For example, suppose you want
163
+ to confirm an action before actually executing it. Add the following to your
164
+ command::
165
+
166
+ $dialog = $this->getHelperSet()->get('dialog');
167
+ if (!$dialog->askConfirmation($output, 'Continue with this action?', false)) {
168
+ return;
169
+ }
170
+
171
+ In this case, the user will be asked "Continue with this action", and unless
172
+ they answer with ``y ``, the task will stop running. The third argument to
173
+ ``askConfirmation `` is the default value to return if the user doesn't enter
174
+ any input.
175
+
176
+ You can also ask questions with more than a simple yes/no answer. For example,
177
+ if you needed to know the name of something, you might do the following::
178
+
179
+ $dialog = $this->getHelperSet()->get('dialog');
180
+ $name = $dialog->ask($output, 'Please enter the name of the widget', 'foo');
181
+
158
182
Testing Commands
159
183
----------------
160
184
You can’t perform that action at this time.
0 commit comments