Is there a way in Silex to define multiple routes for one request. I need to be able to define two routes for one page (both routes takes to the same page). Here's my current controller:
$app->get('/digital-agency', function() use ($app) {
return $app['twig']->render('digital_agency.html', $data);
});
It works when I duplicate the function like this:
$app->get('/digital-agency', function() use ($app) {
return $app['twig']->render('digital_agency.html', $data);
});
$app->get('/agencia-digital', function() use ($app) {
return $app['twig']->render('digital_agency.html', $data);
});
So, any idea of a more clean way to do it?
You can save the closure to a variable and pass that to both routes:
$digital_agency = function() use ($app) {
return $app['twig']->render('digital_agency.html', $data);
};
$app->get('/digital-agency', $digital_agency);
$app->get('/agencia-digital', $digital_agency);
You can also use the assert method to match certain expressions.
$app->get('/{section}', function() use ($app) {
return $app['twig']->render('digital_agency.html', $data);
})
->assert('section', 'digital-agency|agencia-digital');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With