Just set up the processor for the longest URL possible (having all the parts, including optional ones), like this:
$app->get('/controller/{method}/{param}',
function($method, $param) {
// called both by `/controller/some-method/some-param-string`,
// `/controller/some-other-method`, and even `/controller`
});
By default, empty strings are assigned as values of the params that correspond to the omitted URL parts. But you can override this explicitly, as described in the doc:
$app->get('/page/{pageName}', function($pageName) {
// ...
})->value('pageName', 'index');
Now, when /page
is accessed, $pageName
is set to 'index'
.