legomolina
legomolina

Reputation: 1083

Slim framework v3 route conditions

in Slim v2 we had these conditionals to define routes

$app->get('/:route', function($route) use($app) {
    //Code goes here
})->conditions(array('route' => 'route1|route2|route3'));

My question is, how can I replicate this in Slim v3?
Thank you

Upvotes: 3

Views: 1832

Answers (1)

Rob Allen
Rob Allen

Reputation: 12778

Slim 3 uses FastRoute, so the format is: {name:regular expression conditional}.

In your case, you need:

$app->get('/{route:route1|route2|route3}', function($request, $response, $args) {
    $route = $args['route'];
    // code here
});

Upvotes: 13

Related Questions