You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to use php-di to inject route parameters. In my case these are always of type int.
Using this function signature ...
$app->delete("/objects/{objectId}", [MyController::class, 'deleteObject']); // Please ignore the fake callable setup, this is just for demonstration// ...publicfunction deleteObject(Request$request, Response$response, int$objectId)
... and then calling the path of this function with this URL: DELETE /objects/testing/ ...
... produces a standard PHP exception: Argument 4 passed to App\\Controllers\\v2\\DocumentClassController::deleteTableField() must be of the type int, string given
I do understand why this happens and of course I could remove the int type from the function signature and perform my own validation. But' maybe I am missing a more elegant way to catch this exception and automatically respond with a 400 status code.
The text was updated successfully, but these errors were encountered:
You'll get an automatic native 404 from Slim, for anything that doesn't match.
Not sure how invocation could be any "smarter" about such. I think it's already better than native Slim for types (Slim wouldn't even cast input to int, if I remember right).
This is definitely not an issue that concerns Slim-Brige the solution above by @Rarst of using regular expression matching is the way to do it, as it's the framework way and will be handled by the RouteParser.
@fabiante What you want is solved by writing an invocation route strategy, see the Slim docs. If you dont want to learn the Slim internals - you can use my component for the Slim (https://github.com/solventt/slim-route-strategy) - It also solves your problem: a numeric $id argument has an integer type when it comes in a controller method signature. BUT there is only one condition - the name of the controller parameter and the route placeholder MUST be id.
Hi!
I'd like to use php-di to inject route parameters. In my case these are always of type
int
.Using this function signature ...
... and then calling the path of this function with this URL:
DELETE /objects/testing/
...... produces a standard PHP exception:
Argument 4 passed to App\\Controllers\\v2\\DocumentClassController::deleteTableField() must be of the type int, string given
I do understand why this happens and of course I could remove the
int
type from the function signature and perform my own validation. But' maybe I am missing a more elegant way to catch this exception and automatically respond with a400
status code.The text was updated successfully, but these errors were encountered: