Symfony 4 - Composer 更新后,ObjectManager 不存在此类服务

标签 symfony object service composer-php

在我的项目 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/

相关文章:

html - Symfony2 包含在 Twig 的 html 中

php - API平台自定义操作为数据论证提供值(value)

visual-c++ - 初始化 GUID 变量

成员函数中的 C++ 静态变量

java - 使用后台服务播放音乐时,音乐在移动到另一个 Activity 时停止

AngularJS Factory.XXX 不是一个函数

php - Twig 宏可以返回值吗?

symfony - 如何在我的应用程序中从 Monolog 读取日志?

来自 <input type=date> 的 JavaScript 日期对象

c# - .NET ServiceController.WaitForStatus 忽略超时