Skip to content

Commit 2dc7382

Browse files
authored
fix(controller): clarify the use of __invoke for identifiers (#1392)
1 parent b5a8728 commit 2dc7382

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

core/controllers.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ This action will be automatically registered as a service (the service name is t
6868
API Platform automatically retrieves the appropriate PHP entity using the data provider then deserializes user data in it,
6969
and for `POST`, `PUT` and `PATCH` requests updates the entity with data provided by the user.
7070

71-
**Warning: when using `POST` or `PUT`, the `__invoke()` method parameter [MUST be called `$data`](https://symfony.com/doc/current/components/http_kernel.html#getting-the-controller-arguments)**, otherwise, it will not be filled correctly!
72-
When using `GET`, the `__invoke()` method parameter should be called the same as the entity identifier. So for the path `/user/{uuid}/bookmarks`, you must use `__invoke($uuid)`.
71+
**Warning: the `__invoke()` method parameter [MUST be called `$data`](https://symfony.com/doc/current/components/http_kernel.html#getting-the-controller-arguments)**, otherwise, it will not be filled correctly!
7372

7473
Services (`$bookPublishingHandler` here) are automatically injected thanks to the autowiring feature. You can type-hint any service
7574
you need and it will be autowired too.
@@ -287,6 +286,9 @@ App\Entity\Book:
287286
This way, it will skip the `ReadListener`. You can do the same for some other built-in listeners. See [Built-in Event Listeners](events.md#built-in-event-listeners)
288287
for more information.
289288

289+
In your custom controller, the `__invoke()` method parameter should be called the same as the entity identifier.
290+
So for the path `/user/{uuid}/bookmarks`, you must use `__invoke(string $uuid)`.
291+
290292
## Alternative Method
291293

292294
There is another way to create a custom operation. However, we do not encourage its use. Indeed, this one disperses

0 commit comments

Comments
 (0)