So as it stands right now I can have:
<?php
$app->get('/user', function($request, $response, $args) {
/* code */
}):
?>
Which can then correctly resolve to domain.com/user. My problem is when I want to logically group the routes. If I define it like this:
<?php
$app->group('/user', function() use ($app) {
$app->get('/', function($request, $response, $args) {
/* code */
});
});
?>
Then it forces a match to domain.com/user/ (note the trailing slash). Is there a way to set up a group route with a "default" so it doesn't require that trailing slash?
See #1597
Given this set up:
$ mkdir slimtest && cd slimtest/
$ composer require slim/slim ^3.0@RC
$ touch index.php
with this index.php:
<?php
require 'vendor/autoload.php';
$settings = [
'settings' => [
'displayErrorDetails' => true,
],
];
$app = new \Slim\App($settings);
$app->group('/user', function () use ($app) {
$app->get('/', function ($request, $response, $args) {
return $response->write("/user/\n");
});
$app->get('', function ($request, $response, $args) {
return $response->write("/user\n");
});
});
$app->run();
Then running: php -S 0.0.0.0:8888, I get this when I curl:
$ curl http://localhost:8888/user
/user
$ curl http://localhost:8888/user/
/user/
i.e. it works as you would expect.
Note that with #1626, the URI path is very much what-you-see-is-what-you-get. In this case, nothing changes and so to route to /user when your group is /user, you need an empty path in your map:
$app->group('/user', function() use ($app) {
$app->get('', function($request, $response, $args) {
// URL to get here is: /user
});
});
Most helpful comment
Note that with #1626, the URI path is very much what-you-see-is-what-you-get. In this case, nothing changes and so to route to
/userwhen your group is/user, you need an empty path in your map: