i trying use slim's route groups, having trouble getting url parameters pass in.
$app->group('/contest/:id', function($id) use ($api){ error_log('this contest id: '.$id); // id blank... why? $api->authorize('contest', $id); $contest = new contest($id); $app->get('', function() use ($contest, $api){ $data = $contest->getsettings(); $api->output($data); }); $app->get('/settings', function() use ($contest, $api){ $data = $contest->getsettings(); $api->output($data); }); $app->get('/stats', function() use ($contest, $api){ $data = $contest->getstats(); $api->output($data); }); $app->get('/fields', function() use ($contest, $api){ $data = $contest->getfields(); $api->output($data); }); }); why can't access $id in callback function? isn't point of route groups?
i've tried reproduce - last stable release 2.6.2 - , got (probably) same problem you.
warning: missing argument 1 {closure}()
route params in group placed in callback childs:
$app->group('/contest/:id', function() use ($api){ $app->get('', function($id) use ($contest, $api){ $api->authorize('contest', $id); $contest = new contest($id); $data = $contest->getsettings(); $api->output($data); }); }); but yeah it's ugly authorize in every single route, maybe in kind of middleware? think last 1 on docs page looks needs.
edit
oh found this issue, @gisheri got answer of slim maintainer.
Comments
Post a Comment