controllers.php 954 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. use Symfony\Component\HttpFoundation\Request;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\HttpFoundation\JsonResponse;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  7. //Request::setTrustedProxies(array('127.0.0.1'));
  8. $app->get('/', function () use ($app) {
  9. return $app['twig']->render('index.html.twig', array());
  10. })
  11. ->bind('homepage')
  12. ;
  13. $app->error(function (\Exception $e, Request $request, $code) use ($app) {
  14. if ($app['debug']) {
  15. return;
  16. }
  17. // 404.html, or 40x.html, or 4xx.html, or error.html
  18. $templates = array(
  19. 'errors/'.$code.'.html.twig',
  20. 'errors/'.substr($code, 0, 2).'x.html.twig',
  21. 'errors/'.substr($code, 0, 1).'xx.html.twig',
  22. 'errors/default.html.twig',
  23. );
  24. return new Response($app['twig']->resolveTemplate($templates)->render(array('code' => $code)), $code);
  25. });