Skip to content

Commit 0e1013e

Browse files
Lustmoredweaverryan
authored andcommitted
Pump up docs
1 parent 2155865 commit 0e1013e

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

src/LiveComponent/doc/index.rst

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,9 +1160,9 @@ Uploading files
11601160

11611161
.. versionadded:: 2.9
11621162

1163-
The ability to pass arguments to actions was added in version 2.9.
1163+
The ability to upload files to actions was added in version 2.9.
11641164

1165-
Files aren't send to the component by default. You need to use a live action
1165+
Files aren't sent to the component by default. You need to use a live action
11661166
to handle the files and tell the component when the file should be sent:
11671167

11681168
.. code-block:: html+twig
@@ -1176,24 +1176,46 @@ To send a file (or files) with an action use `files` modifier.
11761176
Without an argument it will send all pending files to your action.
11771177
You can also specify a modifier parameter to choose which files should be upload.
11781178

1179-
The files will be available in a regular `$request->files` files bag.
1180-
You can use `data-model` as a key for your files instead of relying on
1181-
input `name` attribute.
11821179

11831180
.. code-block:: html+twig
11841181

11851182
<p>
1186-
<input type="file" name="my_file" data-model="single" />
1183+
<input type="file" name="my_file" />
11871184
<input type="file" name="multiple[]" multiple />
11881185

11891186
{# Send only file from first input #}
1190-
<button data-action="live#action" data-action-name="files(single)|my_action" />
1187+
<button data-action="live#action" data-action-name="files(my_file)|myAction" />
11911188
{# You can chain modifiers to send multiple files #}
1192-
<button data-action="live#action" data-action-name="files(single)|files(multiple[])|my_action" />
1189+
<button data-action="live#action" data-action-name="files(my_file)|files(multiple[])|myAction" />
11931190
{# Or send all pending files #}
1194-
<button data-action="live#action" data-action-name="files|my_action" />
1191+
<button data-action="live#action" data-action-name="files|myAction" />
11951192
</p>
11961193

1194+
The files will be available in a regular `$request->files` files bag::
1195+
1196+
// src/Components/FileUpload.php
1197+
namespace App\Components;
1198+
1199+
use Symfony\Component\HttpFoundation\Request;
1200+
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
1201+
use Symfony\UX\LiveComponent\Attribute\LiveAction;
1202+
use Symfony\UX\LiveComponent\DefaultActionTrait;
1203+
1204+
#[AsLiveComponent]
1205+
class FileUpload
1206+
{
1207+
use DefaultActionTrait;
1208+
1209+
#[LiveAction]
1210+
public function myAction(Request $request)
1211+
{
1212+
$file = $request->files->get('my_file');
1213+
$multiple = $request->files->all('multiple');
1214+
1215+
// Handle files
1216+
}
1217+
}
1218+
11971219
.. tip::
11981220

11991221
Remember that in order to send multiple files from a single input you

0 commit comments

Comments
 (0)