Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 4-在composer更新后,ObjectManager不存在此类服务_Symfony_Object_Service_Composer Php - Fatal编程技术网

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

Symfony 4-在composer更新后,ObjectManager不存在此类服务,symfony,object,service,composer-php,Symfony,Object,Service,Composer Php,在我的Symfony4项目中,我想做一个作曲家更新,这是他做的 但是因为,当我在构造函数中使用ObjectManager时,它会在所有控制器上产生一个错误,如下所示: use Doctrine\Common\Persistence\ObjectManager; /** * Manager * * @var ObjectManager */ private $manager; public function __construct(ObjectM

在我的Symfony4项目中,我想做一个作曲家更新,这是他做的

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

use Doctrine\Common\Persistence\ObjectManager;

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

public function __construct(ObjectManager $manager)
    {
        $this->manager = $manager;
    }
我有这样的错误:

无法自动连线服务“App\Controller\orDismissionController”: 方法“_construct()”的参数“$manager”引用接口 “条令\公共\持久性\对象管理器”,但没有此类服务 存在。您可能应该将此接口别名为现有接口 “条令.orm.default\u实体\u管理器”服务


它适用于我的所有控制器,因为它们都有ObjectManager,我不知道发生了什么事情

这似乎是由于doctrine bundle=>v2.0.0的升级

你必须改变:

  • Symfony\Bridge\doctor\RegistryInterface=>doctor\Common\Persistence\manager注册表
  • 条令\Common\Persistence\ObjectManager=>条令\ORM\EntityManager接口
在“应用程序\存储库\缺席存储库”中,请更新您的构造函数:

public function __construct(\Doctrine\Common\Persistence\ManagerRegistry $registry)
{
    parent::__construct($registry, Address::class);
}

如果没有,您也可以返回到
原则捆绑包的版本1.12.2

作曲家要求条令/条令包1.12.2


类似问题将Symfony 4.2更新为4.4,
实际上,我在所有src/Repository/*
Symfony\Bridge\document\RegistryInterface
->
document\Common\Persistence\ManagerRegistry
正在使用中

RegistryInterface
->
\doctor\Common\Persistence\manager注册表

如果您使用vim(
vi-psrc/Repository/*.php
),那么以下是:

:tabdo %s/Symfony\\Bridge\\Doctrine\\RegistryInterface/Doctrine\\Common\\Persistence\\ManagerRegistry/cg
:tabdo %s/RegistryInterface/\\Doctrine\\Common\\Persistence\\ManagerRegistry/cg

我的站点在4.4.8中运行良好

将ObjectManager的名称空间更改为
条令\Persistence\ObjectManager而不是
条令\Common\Persistence\ObjectManager

Inject
Doctrine\ORM\EntityManagerInterface
而不是
ObjectManager
。但是在文档上,他们注入了ObjectManager:,所以这真的是个问题吗?哦,好的,这是针对服务的。所以,不,问题就解决了。但它在我的存储库上出现了一个新错误:
无法自动连接服务“App\Repository\AbsenceRepository”:方法“\uu construct()”引用接口“Symfony\Bridge\doctor\RegistryInterface”的参数“$registry”,但不存在此类服务。尝试将类型提示改为“条令\Common\Persi-stence\ManagerRegistry”。
虽然是条令在创建repositories时默认放置此类,但我不知道Symfony的版本是什么。可能是4.3.x,这是肯定的。但是是的,我也认为它来自于教义的更新。因此,在我的项目中,我必须用EntityManagerInterface替换所有ObjectManager,用ManagerRegistry替换所有RegistryInterface。现在它看起来不错,但它仍然令人恼火,因为它不是单独发生的,因为如果有一天我的网站在生产中,我做了一个创作更新,有这样的变化,那么该网站将是HS的时候,我知道我必须使用其他类在生产中做一个创作更新可以导致各种有趣的事情发生。有些东西仍然不合算。该学说的调整发生在几年前。可能在Symfony 3生命周期的早期,autowire被引入。对现有正在工作的4.3项目进行composer更新不会导致此类问题。此处的完整文档:使用条令\ORM\EntityManagerInterface;/***经理**@var entitymanager接口*/private$Manager;公共函数uu构造(EntityManagerInterface$manager){$this->manager=$manager;}在Doctrine 1.3及更高版本中,您应该使用:use Doctrine\Persistence\ManagerRegistry;使用条令\通用\持久性\管理注册表;已在1.3版上弃用。编辑:在Symfony 4中,条令没有将新类与适当的服务相一致,因此中断。使用\doctor\Common\Persistence\manager注册表,直到修复为止。