How to define multiple routes for a single request in Silex?

Is there a way in Silex to define multiple routes for a single request. I need to define two routes for one page (both routes are taken on one page). Here is my current controller:

$app->get('/digital-agency', function() use ($app) { return $app['twig']->render('digital_agency.html', $data); }); 

It works when I duplicate a function as follows:

 $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 cleaner way to do this?

+7
php symfony silex
source share
2 answers

You can save the closing of a variable and pass this 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); 
+14
source share

You can also use the assert method to match specific expressions.

 $app->get('/{section}', function() use ($app) { return $app['twig']->render('digital_agency.html', $data); }) ->assert('section', 'digital-agency|agencia-digital'); 
+10
source share

All Articles