0
votes

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?

2
error pages will be same for all users or only for some users? If it is same for all users, you dont need to override twigbundle or create route for it.Tejas Gosai

2 Answers

0
votes

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

0
votes

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!