in my project symfony 4 I wanted to make a Composer update, something he did.
But since, it puts me an error on all my controllers when I use the ObjectManager in my constructors, like this :
use Doctrine\Common\Persistence\ObjectManager;
/**
* Manager
*
* @var ObjectManager
*/
private $manager;
public function __construct(ObjectManager $manager)
{
$this->manager = $manager;
}
I've this kind of error :
Cannot autowire service "App\Controller\OrdreMissionController": argument "$manager" of method "__construct()" references interface "Doctrine\Common\Persistence\ObjectManager" but no such service exists. You should maybe alias this interface to the existing "doctrine.orm.default_entity_manager" service.
It applies to all my controllers since they all have the ObjectManager, I do not understand what is happening
This seems to be due to the upgrade of doctrine-bundle => v2.0.0.
You have to change :
In your "App\Repository\AbsenceRepository" please update your constructor:
public function __construct(\Doctrine\Common\Persistence\ManagerRegistry $registry)
{
parent::__construct($registry, Address::class);
}
Similar issue to update Symfony 4.2 to 4.4,
In practice, I search/replace in all my src/Repository/*Symfony\Bridge\Doctrine\RegistryInterface
-> Doctrine\Common\Persistence\ManagerRegistry
in USE
andRegistryInterface
-> \Doctrine\Common\Persistence\ManagerRegistry
in __construct
if you use vim (vi -p src/Repository/*.php
), here are:
:tabdo %s/Symfony\\Bridge\\Doctrine\\RegistryInterface/Doctrine\\Common\\Persistence\\ManagerRegistry/cg
:tabdo %s/RegistryInterface/\\Doctrine\\Common\\Persistence\\ManagerRegistry/cg
and my site works fine in 4.4.8
If not you can also come back to version 1.12.2 of doctrine-bundle
composer require doctrine/doctrine-bundle 1.12.2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With