2015-10-04 28 views
6

我在使用参数在Slim 3 RC中工作时遇到问题。Slim 3和内置PHP服务器的路由参数

$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的建议和this question接受的答案,但它不起作用。有什么建议吗?

回答

7

从修身3,你需要在{name}改变:name

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

你可以找到文档here

+1

谢谢。令人惊讶的是,我在调试这个版本时查看了特定于version3的文档,但不知何故错过了语法修改:-) – gazareth