我在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']);
});
你可以在这里找到文档