Kévin Duguay
Kévin Duguay

Reputation: 761

Symfony customizing error 404 and 500

I read the Symfony (http://symfony.com/doc/current/cookbook/controller/error_pages.html#testing-error-pagesdocumentation) and did what they say:

I created 2 files, error404.html.twig and error500.html.twig in the directory (myproject)/app/Resources/TwigBundle/views/Exception/

And I changed the routing_dev.yml file like this:

_wdt:
    resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
    prefix:   /_wdt

_profiler:
    resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
    prefix:   /_profiler

_configurator:
    resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
    prefix:   /_configurator

_main:
    resource: routing.yml

_errors:
    resource: "@TwigBundle/Resources/config/routing/errors.xml"
    prefix:   /_error

When I try to see what it looks like with http://localhost:8080/portfolio/web/app_dev.php/_error/404

I get the following error:

FileLoaderLoadException: Cannot import resource "@TwigBundle/Resources/config/routing/errors.xml" from "C:\xampp\htdocs\portfolio\app/config/routing_dev.yml". Make sure the "TwigBundle/Resources/config/routing/errors.xml" bundle is correctly registered and loaded in the application kernel class.

I checked my AppKernel.php file and it seems like twigBundle IS imported:

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new AppBundle\AppBundle(),
            new PublicBundle\PublicBundle(),
            new AdminBundle\AdminBundle(),
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
    }
}

What's the probleme?

Upvotes: 0

Views: 966

Answers (2)

K&#233;vin Duguay
K&#233;vin Duguay

Reputation: 761

I found the probleme. It's actually really funny.

I was using Symfony 2.5.2, the but the feature I was trying to use was for Symfony 2.6

So I created a new project in 2.6, replace et reconfigure my folders and files and BOOM! it wotks!

Upvotes: 0

Nawfal Serrar
Nawfal Serrar

Reputation: 2263

You can do that without creating a custom bundle for this unless it is necessary.

http://symfony.com/doc/current/cookbook/controller/error_pages.html

create an error.html.twig under app/Resources/TwigBundle/views/Exception/error.html.twig and so on for other special errors like : app/Resources/TwigBundle/views/Exception/error404.html.twig

Upvotes: 0

Related Questions