0

我只想在“事件”对象上创建一个 crud api。索引路由运行良好,但特定事件的路由无法按预期运行

这就是我在“routes.php”中所拥有的

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

我希望使用以下方法在处理程序中恢复 id: $id = $request->getAttribute('id');

但是只有当我按字面意思输入 '/events/:id' 时,才能识别路线,在这种情况下,到达处理程序但 id 为空(如预期的那样)

另一方面,如果我输入 '/events/4' 结果是:“Cannot GET http://localhost/event/4

4

1 回答 1

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}.

于 2019-05-12T20:33:12.320 回答