我需要使用可以包含斜杠 / 的参数来编写 URL。例如,经典的/hello/{username}
路线。默认情况下,/hello/Fabien
将匹配此路线,但不匹配/hello/Fabien/Kris
。我想问你如何在 Slim 3 框架中做到这一点。
路线占位符 http://www.slimframework.com/docs/objects/router.html#route-placeholders:
对于“无限”可选参数,您可以这样做:
$app->get('/hello[/{params:.*}]', function ($request, $response, $args) {
$params = explode('/', $request->getAttribute('params'));
// $params is an array of all the optional segments
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)