Symfony - DoctrineBundle未在您的应用程序中注册

时间:2017-11-20 08:27:25

标签: php symfony doctrine symfony-flex

我对Doctrine Bundle有疑问。当我尝试进入网页时,我有错误:

  

DoctrineBundle未在您的申请中注册。

这很奇怪,因为在config / bundles.php中我有:

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],
];

如何添加Doctrine Bundle可用于应用程序?或者可能是教义/学习的东西? 谢谢你的帮助。

修改

当我在控制器中转储$ this时,在services.kernel.bundles中我有:

["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 个答案:

答案 0 :(得分:0)

试试这个;将该行添加到app / AppKernel.php文件中。

new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),

文件看起来像。

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');
    }
}

答案 1 :(得分:0)

我也有这个问题,我快要疯了。原来,出于某些怪异的原因,我之前已经在config.yml中注释了Doctrine配置。