Skip to content

Instantly share code, notes, and snippets.

@dator-zz
Created November 25, 2010 16:23
Show Gist options
  • Save dator-zz/715592 to your computer and use it in GitHub Desktop.
Save dator-zz/715592 to your computer and use it in GitHub Desktop.
#...
parameters:
exception_listener.controller: "YourBundle:Exception:exception"
<?php
namespace Application\YourBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\FlattenException;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
class ExceptionController extends Controller
{
/**
* Converts an Exception to a Response.
*
* @param FlattenException $exception A FlattenException instance
* @param DebugLoggerInterface $logger A DebugLoggerInterface instance
* @param string $format The format to use for rendering (html, xml, ...)
* @param Boolean $embedded Whether the rendered Response will be embedded or not
*
* @throws \InvalidArgumentException When the exception template does not exist
*/
public function exceptionAction(FlattenException $exception, DebugLoggerInterface $logger = null, $format = 'html', $embedded = false)
{
switch($exception->getCode()){
case 404:
$tpl = '404';
break;
default:
$tpl = 'error';
break;
}
// for example of course :)
return $this->render('YourBundle:Exception:'.$tpl.'.php', array(
'exception' => $exception,
));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment