Symfony - DoctrineBundle is not registered in your application

Viewed 2591

I have a problem with Doctrine Bundle. When i try entry to webpage i have error:

The DoctrineBundle is not registered in your application.

It's strange because in config/bundles.php i has:

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    FOS\RestBundle\FOSRestBundle::class => ['all' => true],
    JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true],
    Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
];

How to add Doctrine Bundle avalible for application? OR maybe is something with doctrine/orm? Thanks for any help.

EDIT

When i dump $this in controller, in services.kernel.bundles i have:

["DoctrineBundle"]=>
          object(Doctrine\Bundle\DoctrineBundle\DoctrineBundle)#73 (6) {
            ["autoloader":"Doctrine\Bundle\DoctrineBundle\DoctrineBundle":private]=>
            NULL
            ["name":protected]=>
            string(14) "DoctrineBundle"
            ["extension":protected]=>
            NULL
            ["path":protected]=>
            NULL
            ["namespace":"Symfony\Component\HttpKernel\Bundle\Bundle":private]=>
            string(30) "Doctrine\Bundle\DoctrineBundle"
            ["container":protected]=>
            *RECURSION*
          }
        }
2 Answers

Try this; add the line into app/AppKernel.php file.

new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),

File looks like it.

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 Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new DashboardBundle\DashboardBundle(),
            new Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle(),
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $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($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
    }
}

I had this problem too and I was going crazy. Turns out I had previously commented out the Doctrine configuration in config.yml for some spooky reason.

Related