0

How can I have or-option in the Slim 3 routes?

For instance, this is what I do currently:

// Home page.
$app->get('/', function (Request $request, Response $response, array $args) {
    // Get the application settings.
    $settings = $this->get('settings');

    // Check if the home page class is provided.
    ... lots of codes
});

$app->get('/home', function (Request $request, Response $response, array $args) {
    // Get the application settings.
    $settings = $this->get('settings');

    // Check if the home page class is provided.
    ... lots of codes
});

instead of repeating the chunks of these codes, can I make them into one like:

$app->get('/ or /home', function (Request $request, Response $response, array $args) {
...}
Run
  • 54,938
  • 169
  • 450
  • 748

1 Answers1

1

Optional segments is what you're looking for.

Evgeny Soynov
  • 704
  • 3
  • 13