Symfony 4 - 作曲家更新后,ObjectManager 不存在此类服务

ero*_*onn 16 service object symfony composer-php

在我的项目 symfony 4 中,我想对 Composer 进行更新,这是他所做的。

但是因为,当我在构造函数中使用 ObjectManager 时,它会在我的所有控制器上显示一个错误,如下所示:

use Doctrine\Common\Persistence\ObjectManager;

/**
     * Manager
     *
     * @var ObjectManager
     */
    private $manager;

public function __construct(ObjectManager $manager)
    {
        $this->manager = $manager;
    }
Run Code Online (Sandbox Code Playgroud)

我有这种错误:

无法自动装配服务“App\Controller\OrdreMissionController”:方法“__construct()”的参数“$manager”引用接口“Doctrine\Common\Persistence\ObjectManager”,但不存在这样的服务。您可能应该将此接口别名为现有的“doctrine.orm.default_entity_manager”服务。

它适用于我所有的控制器,因为它们都有 ObjectManager,我不明白发生了什么

小智 35

这似乎是由于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);
}
Run Code Online (Sandbox Code Playgroud)