php - Define Silex routes as it goes -
is possible define silex routes route definition goes. instance, define following routes depending on previous routes are:
/a/{user}/{app_name}/list/ -> /a/{user}/{app_name}/list/{id}/ /a/{user}/{app_name}/add/ -> /a/{user}/{app_name}/add/success/ /a/{user}/{app_name}/help/ -> no sub route
here 5th route should {id}
when 4th list
or success
when 4th add
or nothing when 4th help
. don't know how in silex:
$app -> get('/a/{user}/{app_name}/{action}/{sub}/', function (silex\application $app, $user, $app_name, $action, $sub) { ... });
which doesn't work of them.
is there way this:
$app -> get('/a/{user}/{app_name}/{action}/', function (silex\application $app, $user, $app_name, $action) { if ($action == 'list') { $app -> get('/a/{user}/{app_name}/{action}/{id}', function (silex\application $app, $user, $app_name, $action, $id) { ... }); } elseif ($action == 'add') { $app -> get('/a/{user}/{app_name}/{action}/success', function (silex\application $app, $user, $app_name, $action) { ... }); } });
the actions list, add, help, etc. indefinite defined users create simple apps in our system. there's no way can directly hard code them in code. after routing goes specific user app e.g. /a/jim/cook
actions available.
is possible? how?
found solution @ answer: https://stackoverflow.com/a/15214674/49318
$app->get('/pdf/{template}/{args}', function ($template, $args) { ... }) ->assert('args', '.*') ->convert('args', function ($args) { return explode('/', $args); });
Comments
Post a Comment