Skip to content

Instantly share code, notes, and snippets.

@iign
Created June 4, 2015 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iign/cfe92508e4041665f6ae to your computer and use it in GitHub Desktop.
Save iign/cfe92508e4041665f6ae to your computer and use it in GitHub Desktop.
Silex index.php file
require_once __DIR__ . '/vendor/autoload.php';
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$app = new Silex\Application();
// $app['debug'] = true;
$app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/views',
));
// Home page
$app->get('/', function() use($app) {
return $app['twig']->render('index.html');
})->bind('index');
// Other page
$app->get('/other', function() use($app) {
return $app['twig']->render('other.html');
})->bind('other');
// 404 - Page not found
$app->error(function (\Exception $e, $code) use ($app) {
switch ($code) {
case 404:
return $app['twig']->render('404.html', array('lang' => 'es', 'short_url' => '404'));
$message = 'The requested page could not be found.';
break;
default:
$message = 'We are sorry, but something went terribly wrong.';
}
return new Response($message);
});
$app->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment