Skip to content

Commit 7be946d

Browse files
committed
Pump up docs
1 parent 1ca6b69 commit 7be946d

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
@@ -1163,9 +1163,9 @@ Uploading files
11631163

11641164
.. versionadded:: 2.9
11651165

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

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

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

1182-
The files will be available in a regular `$request->files` files bag.
1183-
You can use `data-model` as a key for your files instead of relying on
1184-
input `name` attribute.
11851182

11861183
.. code-block:: html+twig
11871184

11881185
<p>
1189-
<input type="file" name="my_file" data-model="single" />
1186+
<input type="file" name="my_file" />
11901187
<input type="file" name="multiple[]" multiple />
11911188

11921189
{# Send only file from first input #}
1193-
<button data-action="live#action" data-action-name="files(single)|my_action" />
1190+
<button data-action="live#action" data-action-name="files(my_file)|myAction" />
11941191
{# You can chain modifiers to send multiple files #}
1195-
<button data-action="live#action" data-action-name="files(single)|files(multiple[])|my_action" />
1192+
<button data-action="live#action" data-action-name="files(my_file)|files(multiple[])|myAction" />
11961193
{# Or send all pending files #}
1197-
<button data-action="live#action" data-action-name="files|my_action" />
1194+
<button data-action="live#action" data-action-name="files|myAction" />
11981195
</p>
11991196

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

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

0 commit comments

Comments
 (0)