Skip to content

Instantly share code, notes, and snippets.

@dflima
Created December 28, 2012 18:55
Show Gist options
  • Select an option

  • Save dflima/4400784 to your computer and use it in GitHub Desktop.

Select an option

Save dflima/4400784 to your computer and use it in GitHub Desktop.
Dynamic routing on silex
<?php
require_once __DIR__.'/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$app = new Silex\Application();
// Twig
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/../templates',
'twig.options' => array('cache'=>__DIR__.'/../templates_c'),
));
$pages = array(
'/' => 'index',
'/blog' => 'blog',
'/about' => 'about',
);
foreach($pages as $route => $view) {
$api->get($route, function(Silex\Application $app) use($view) {
return $app['twig']->render($view.'.html');
})->bind($view);
}
return $app;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment