Created
November 25, 2010 16:23
-
-
Save dator-zz/715592 to your computer and use it in GitHub Desktop.
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
#... | |
parameters: | |
exception_listener.controller: "YourBundle:Exception:exception" |
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
<?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