-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: Clarify __invoke distinction #1358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The invoke method parameter differs from POST to GET methods.
Are you sure it's the case? Where is the attribute set? |
add comma for readability Co-authored-by: Alan Poulain <[email protected]>
Language update Co-authored-by: Alan Poulain <[email protected]>
When I have this entity:
And I do this in my controller
I get: But it works if I do
Which leads me to believe that the argument name must match the identifier name |
OK I see why now, it's because the route parameters are given directly to the controller method. |
@@ -65,7 +65,8 @@ This action will be automatically registered as a service (the service name is t | |||
API Platform automatically retrieves the appropriate PHP entity using the data provider then deserializes user data in it, | |||
and for `POST` and `PUT` requests updates the entity with data provided by the user. | |||
|
|||
**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! | |||
**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! | |||
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)`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's wrong: the cause was not (only) you using GET
but "read": false
(I have used GET
with $data
, working)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also retrieve the identifier even if read
is true
. But you are right, it should be modified to say that is also works for GET
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See: #1392
When creating custom controllers the invoke method parameter name differs depending on the HTTP method.