0

I just want to make a crud api over an "Event" object. Routes for index works well but the route for an specific event doesn't work as expected

this is what I have in 'routes.php'

$app->get('/event/:id', \App\Handler\EventRecoverHandler::class, 'event.withId');

I expect to recover the id in the handler using: $id = $request->getAttribute('id');

but the route only get recognized if I put '/events/:id' literally, in this case the handler is reached but the id is null (as expected)

on the other hand if I put '/events/4' the result is: "Cannot GET http://localhost/event/4"

ricky
  • 105
  • 1
  • 6

1 Answers1

2

The problem was that I was following the examples provided in routes.php file, they say that in order to use route parameters you should use /path/:parameter

i don't know what router packages does use this sintax but in my case I was using FastRoute (the default zend expressive installer selection) and the right sintax is (following fast route documentation) /path/{parameter}.

ricky
  • 105
  • 1
  • 6
  • That example configuration is from zend-router. I've opened an issue which should address this: https://github.com/zendframework/zend-expressive-skeleton/issues/272 – xtreamwayz May 13 '19 at 07:55