Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slim 3 - Slash as a part of route parameter

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.

like image 226
User Avatar asked Aug 29 '16 10:08

User


2 Answers

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
});
like image 170
revo Avatar answered Oct 31 '22 19:10

revo


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
});
like image 1
Anuga Avatar answered Oct 31 '22 20:10

Anuga