Created
June 4, 2015 17:38
-
-
Save iign/cfe92508e4041665f6ae to your computer and use it in GitHub Desktop.
Silex index.php file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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