Slim: slim 3 route wildcard

Created on 23 Dec 2015  路  2Comments  路  Source: slimphp/Slim

In slim 3 i'm trying to define a wildcard route - something to catch all url typos
Below my code

$app->get('/.*', function (Request $request, Response $response) {
$response->getBody()->write("MY MESSAGE");
return $response;
});

However all I get is a Page Not Found. With all the changes in version 3 have I missed something?

Most helpful comment

This works:

$app->get('/[{path:.*}]', function($request, $response, $path = null) {
    return $response->write($path ? 'subroute' : 'index');
});

About optional part you can read here: http://www.slimframework.com/docs/objects/router.html#any-route and https://github.com/nikic/FastRoute/blob/master/README.md

All 2 comments

This works:

$app->get('/[{path:.*}]', function($request, $response, $path = null) {
    return $response->write($path ? 'subroute' : 'index');
});

About optional part you can read here: http://www.slimframework.com/docs/objects/router.html#any-route and https://github.com/nikic/FastRoute/blob/master/README.md

Thank you.
It worked.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexweissman picture alexweissman  路  38Comments

l0gicgate picture l0gicgate  路  31Comments

feryardiant picture feryardiant  路  20Comments

l0gicgate picture l0gicgate  路  50Comments

akrabat picture akrabat  路  43Comments