Welcome to Abdul Malik Ikhsan's Blog

Symfony 2.6.1 : Using class_alias of Debug’s FlattenException to work with Error page previews

Posted in Symfony2 Framework, Tutorial PHP by samsonasik on December 19, 2014

Error page previews is one of the new features that land in Symfony 2.6. You should be able to access /_error/{statusCode}.{format}. Unfortunatelly, when I try in Symfony 2.6.1, It doesn’t work. The reason of issue is that in TwigBundle\Controller\ExceptionController::showAction() require HttpKernel’s FlattenException that should be require Debug’s FlattenException.
The HttpKernel’s FlattenException is deprecated from Symfony 2.3 and should be removed in 3.0.
If you see the Symfony\Bundle\TwigBundle\Controller\ExceptionController, you will see :

use Symfony\Component\HttpKernel\Exception\FlattenException;
// ...
// ...
    public function showAction(
       Request $request,
       FlattenException $exception,
       DebugLoggerInterface $logger = null)

// ...
// ...

So, You just cannot make custom exception that extends the ExceptionController because of the typehint requirement. What we can do ? The issue already reported in github so we just can wait to make it work in next maintenance release – OR – do tricky in the skeleton! Don’t do it in vendor libraries directly. You shouldn’t touch it anymore. We can edit our symfony-standard skeleton application in web/app_dev.php by apply class_alias after loader loaded :

// web/app_dev.php
// ...
$loader = require_once __DIR__.'/../app/bootstrap.php.cache';
// ...

That’s it, so when you try access : or whatever your Symfony url skeleton application with /_error/404.html, you will get something like this :


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: