2
votes

I would like to TOTALLY disable the twig error pages in Symfony. I do not want to customize them as described here: http://symfony.com/doc/2.0/cookbook/controller/error_pages.html but rather simply unplug the exception handling mechanism of twig and end up with plain good old php errors.

Is it possible at all?

2
If I may be so bold as to ask why you want to go with native php errors? Errors should never be displayed to the user, and during dev/QA you should run in an environment that shows the rrorsMrGlass
I just hate em. I am more confy with ugly messages that's it. ANy idea how to do it?nourdine
You might have better luck using only some of the symfoyn components, instead of the whole package. you can read up on the components here symfony.com/doc/current/components/index.htmlMrGlass

2 Answers

10
votes

To disable twig error pages you can just add something like

services:
   twig.exception_listener:
     class: DateTime #or another dummy class

to your app/config.yml

After this you will see much simple screen produced by Symfony\Component\HttpKernel\Debug\ExceptionHandler. If you want to remove this behavior - replace this class or just comment set_exception_handler call in.

public static function register($debug = true)
{
    $handler = new static($debug);

    set_exception_handler(array($handler, 'handle'));

    return $handler;
}
0
votes

In Symfony 3.x, this is how it can be done:

To services.yml, add the listener override (as in @Ziumin's answer):

services:
  twig.exception_listener:
    class: stdObject

In app_dev.php, comment out the line Debug::enable();, which will disable even the simplified error handling page (and then there's no need to modify files from the framework).

Then after that, you can add your own exception handler:

// Disable error handling page:
// Debug::enable();

set_exception_handler(function($e) {
    $msg = array();
    $msg[] = 'Exception: ' . $e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine();
    $msg[] = '';
    $msg[] = $e->getTraceAsString();
    echo implode("\n", $msg);
});