slim optional route parameter suffix not working -
i want define route have .suffix param in end. want use in app return user needs. eg .json or .xml or none!. how should define route? example address want:
/user/all.json
or
/user/all.xml
or
/user/all # default json
this route defined. it's not working expected.
/user/:method(\.(:type))
in slim route segments defined forward slash, , not interchangeably dot. however, can either add logic route closure, or add route conditions multiple routes.
in closure:
$app->get('/user/:methodtype', function ($methodtype) { if ($path = explode($methodtype, '.')) { if ($path[1] === 'json') { // json... } elseif ($path[1] === 'xml') { // xml... } } });
or use route conditions, 1 each mutually exclusive:
// json requests $app->get('/user/:methodtype', function ($methodtype) { // json... })->conditions(array('methodtype' => '.json$')); // xml requests $app->get('/user/:methodtype', function ($methodtype) { // xml... })->conditions(array('methodtype' => '.xml$'));