我需要使用可以包含斜杠 / 的参数来编写 URL。比如经典/hello/{username}
路线。默认情况下,/hello/Fabien
将匹配此路由但不匹配/hello/Fabien/Kris
. 我想问你如何在 Slim 3 框架中做到这一点。
问问题
1509 次
2 回答
7
对于“无限”可选参数,您可以这样做:
$app->get('/hello[/{params:.*}]', function ($request, $response, $args) {
$params = explode('/', $request->getAttribute('params'));
// $params is an array of all the optional segments
});
于 2016-08-29T10:31:20.323 回答
1
您也可以使用$args
:
$app->get('/hello[/{route:.*}]', function ($request, $response, $args) {
$route = $args['route']; // Whole Route
$params = explode('/', $route); // Route split
});
于 2018-10-25T07:30:59.800 回答