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
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?