Doctrine cannot map entity/repository namespace in chain

后端 未结 4 1841
暗喜
暗喜 2021-01-24 17:44

I\'m trying to setup symfony with doctrine, configuring doctrine is new for me.

I try to retrieve a entity from the database by using the following code in my controller

4条回答
  •  悲&欢浪女
    2021-01-24 18:12

    After a long struggle I found out what caused the problem. My symfony environment was running in prod mode. I switched to dev. And it all worked like a charm.

    But i'm still wondering why?! I checked The AppKernel.php and it looks like:

    $bundles = [
        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 AppBundle\AppBundle(),
    ];
    
    if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
        $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
        $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
        $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
    
        if ('dev' === $this->getEnvironment()) {
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
            $bundles[] = new Symfony\Bundle\WebServerBundle\WebServerBundle();
        }
    }
    
    return $bundles;
    

    It seems to me no matter what environment I run, doctrine is loaded. Can somebody explain to me the reason behind this behaviour.

    EDIT:

    I discovered something more, I switched to prod environment again but now I started flipping debugging on/off.

    Now I see that is works nicely in production mode but only when debugging is enabled. Why?

提交回复
热议问题