There was an error in this gadget

Friday, March 11, 2011

How to custmize the error page in Symfony2

We can see the new character, which name I don't know at the error page.

Speaking of the character, there is an unofficial symfony character, which name is "Symfonyan".

Symfonyan is "Symfony" + "Nayn". "Nyan" is Japanese which mean mew. She is pretty :D

So, I tried to change the character to Symfonyan in this error page.

How to customize the error page


At the first, I read the documentation Symfony - How to customize Error Pages. But I could not custmize it! Perhaps the path where we put the customized html is changed in PR7. So I read the source code and I saw the correct path.

So I decided to make an original bundle, "SymfonyanBundle" because of making everyone use it easily.

How to install SymfonyanBundle


the source code of SymfonyanBundle is managed in Github. So you can install it by git command.
$ git clone git://github.com/brtriver/SymfonyanBundle.git src/Acme/SymfonyanBundle

You have to add this bundle in app/AppKernel.php

....
if (in_array($this->getEnvironment(), array('dev', 'test'))) {
    $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
    $bundles[] = new Symfony\Bundle\WebConfiguratorBundle\SymfonyWebConfiguratorBundle();
    $bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
    $bundles[] = new Acme\SymfonyanBundle\SymfonyanBundle(); // <= addition
}


Confirm by the console. If you can add this bundle, you can see like below.
$ ./app/console
...
symfonyan
:exception-install Change the icon of the exception page to Symfonyan
:welcome-install Change the welcome page to Symfonyan

At the last, you have only to run this command from console. It's very simple and easy!

$ ./app/console symfonyan:exception-install --symlink
$ ./app/console assets:install web --symlink

Result


[404 in development env]

[404 in production env]

cute!

One more thing

You can customize the default welcome page with Symfonyan. It's easy to run the command below.

$ ./app/console symfonyan:welcome-install --symlink
The default page is translated to Japanese, too :)

No comments:

Post a Comment