Slim 3 - Slash as a part of route parameter

安稳与你 提交于 2019-12-10 16:17:53

问题


I need to compose URLs with parameters that can contain a slash /. For example, the classic /hello/{username} route. By default, /hello/Fabien will match this route but not /hello/Fabien/Kris. I would to ask you how can I do it in Slim 3 framework.


回答1:


Route placeholders:

For “Unlimited” optional parameters, you can do this:

$app->get('/hello[/{params:.*}]', function ($request, $response, $args) {
    $params = explode('/', $request->getAttribute('params'));

    // $params is an array of all the optional segments
});



回答2:


You can just as well use $args:

$app->get('/hello[/{route:.*}]', function ($request, $response, $args) {
    $route = $args['route']; // Whole Route
    $params = explode('/', $route); // Route split
});


来源:https://stackoverflow.com/questions/39203681/slim-3-slash-as-a-part-of-route-parameter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!