在我的项目 symfony 4 中,我想对 Composer 进行更新,他做到了。
但是,当我在构造函数中使用 ObjectManager 时,它会给我的所有 Controller 带来错误,如下所示:
use Doctrine\Common\Persistence\ObjectManager;
/**
* Manager
*
* @var ObjectManager
*/
private $manager;
public function __construct(ObjectManager $manager)
{
$this->manager = $manager;
}
我遇到了这样的错误:
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.
它适用于我的所有 Controller ,因为它们都有 ObjectManager,我不明白发生了什么
最佳答案
这似乎是由于doctrine-bundle => v2.0.0的升级所致。
你必须改变:
- Symfony\Bridge\Doctrine\RegistryInterface => Doctrine\Common\Persistence\ManagerRegistry
- Doctrine\Common\Persistence\ObjectManager => Doctrine\ORM\EntityManagerInterface
在您的“App\Repository\AbsenceRepository”中,请更新您的构造函数:
public function __construct(\Doctrine\Common\Persistence\ManagerRegistry $registry)
{
parent::__construct($registry, Address::class);
}
关于Symfony 4 - Composer 更新后,ObjectManager 不存在此类服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58954082/