Symfony 2. How to catch the Exception parameter in a Twig template?

I am throwing some kind of exception to my controller.

For example:

throw new AccessDeniedHttpException('some_text');

How can I catch this 'some_text' parameter in my Twig template.

I found the variables {{status_code}} and {{status_text}}, but I can not find something similar that solves my problem.

PS I am already using a custom error page. I just want to give users specific explanations about the errors.

Thnx.

+4
source share
2 answers

By default, Symfony uses showActionof Symfony\Bundle\TwigBundle\Controller\ExceptionControllerto display your error page. The implementation in Symfony 2.3 looks like this:

public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null, $_format = 'html')
{
    $currentContent = $this->getAndCleanOutputBuffering($request->headers->get('X-Php-Ob-Level', -1));

    $code = $exception->getStatusCode();

    return new Response($this->twig->render(
        $this->findTemplate($request, $_format, $code, $this->debug),
        array(
            'status_code'    => $code,
            'status_text'    => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : '',
            'exception'      => $exception,
            'logger'         => $logger,
            'currentContent' => $currentContent,
        )
    ));
}

, 'exception' => $exception, . $exception Symfony\Component\HttpKernel\Exception\FlattenException, PHP Exception.

FlattenException::getMessage, , . . FlattenException API.

+4

Ok. TWIG

{{ exception.message|nl2br }}
+2

All Articles