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.
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
:
$app->get('/hello[/{route:.*}]', function ($request, $response, $args) {
$route = $args['route']; // Whole Route
$params = explode('/', $route); // Route split
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With