简体   繁体   English

Slim 3 - 斜线作为路径参数的一部分

[英]Slim 3 - Slash as a part of route parameter

I need to compose URLs with parameters that can contain a slash /. 我需要使用包含斜杠/的参数来组合URL。 For example, the classic /hello/{username} route. 例如,经典/hello/{username}路由。 By default, /hello/Fabien will match this route but not /hello/Fabien/Kris . 默认情况下, /hello/Fabien将匹配此路由,但不匹配/hello/Fabien/Kris I would to ask you how can I do it in Slim 3 framework. 我想问你怎么能在Slim 3框架中做到这一点。

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
});

You can just as well use $args : 你也可以使用$args

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM