Skip to content

Instantly share code, notes, and snippets.

@silentworks
Last active November 7, 2015 00:13
Show Gist options
  • Save silentworks/0a9b03b69861dcb1d828 to your computer and use it in GitHub Desktop.
Save silentworks/0a9b03b69861dcb1d828 to your computer and use it in GitHub Desktop.
Route Groups
<?php
$app->group('/', function () {
$app->get('/about', function ($req, $res) {
return $res->getBody()->write('About this site.');
})->setName('about');
$app->get('/services', function ($req, $res) {
return $res->getBody()->write('Services we offer.');
})->setName('services');
$app->get('/contact', function ($req, $res) {
return $res->getBody()->write('Contact this site.');
})->setName('contact');
});

The above code is broken because each route would return the following:

  • //about
  • //services
  • //contact

All these paths will be absolute url when using pathFor.

If the group was to be changed to be $app->group('', fun...) this would cause an error with FastRoute if the first get route is $app->get('/', fun...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment