路由参数与Slim 3 &内置PHP服务器


Route parameters with Slim 3 & built-in PHP server

我在Slim 3 RC中获得带有参数的路由时遇到问题。

$app->get('/hello/:name', function($req, $res, $args) {
    echo "Hello {$name}";
});

访问/hello/joe结果为404。

其他路由也可以,例如:

$app->get('/', HomeAction::class . ":dispatch");
$app->get('/services', ServicesAction::class . ":dispatch");

我正在使用内置的PHP服务器,而我正在开发。我没有.htaccess文件。我已经尝试了建议的route.php建议和接受这个问题的答案,但它不起作用。有什么建议吗?

从Slim 3你需要改变{name}中的:name

$app->get('/hello/{name}', function ($request, $response, $args) {
    return $response->write("Hello " . $args['name']);
});

你可以在这里找到文档