【问题标题】:Error: Argument 1 passed to App\Repository\FooRepository::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry错误:传递给 App\Repository\FooRepository::__construct() 的参数 1 必须是 Doctrine\Common\Persistence\ManagerRegistry 的一个实例
【发布时间】:2020-09-01 13:41:33
【问题描述】:

更新到doctrine/doctrine-bundle 2.1.2 后出现此错误:

传递给 App\Repository\FooRepository::__construct() 的参数 1 必须是 Doctrine\Common\Persistence\ManagerRegistry 的实例,给定的 Doctrine\Bundle\DoctrineBundle\Registry 的实例,在...中调用

我的存储库如下所示:

namespace App\Repository;

use App\Entity\Foo;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Common\Persistence\ManagerRegistry;

class FooRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Foo::class);
    }
}

=> 在下面查看我自己的答案。

【问题讨论】:

    标签: php symfony doctrine-orm


    【解决方案1】:

    只需更改此 use

    use Doctrine\Common\Persistence\ManagerRegistry;
    

    use Doctrine\Persistence\ManagerRegistry;
    

    文档:https://symfony.com/doc/current/doctrine.html#querying-for-objects-the-repository

    【讨论】:

    • 这不是真的,答案是正确的!我刚刚遇到了同样的问题,并按照答案中的说明更改了“use ...”行。
    • 太棒了,在 Symfony 4.4 上运行 composer updatedoctrine/common2.x 提升到 3.0.2 - 在没有任何通知的情况下破坏所有以前生成的 Repository 类。太棒了。我喜欢做一些小的更新并让我的代码库中断。
    • @Roger 我也有同样的问题,请问您还有其他重大更改吗?
    • @Roger 如果您使用上述类,但没有将提供它们的依赖项固定在您的 composer.json 中,那么您就是在自找麻烦。
    • @gregOire - 但如果您确实将它们固定在 composer.json 中,那么您会在该次要更新中遇到非常混乱的版本冲突。
    猜你喜欢
    • 2018-01-22
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    • 2018-12-15
    • 1970-01-01
    • 2018-08-30
    • 2018-01-09
    • 2021-05-16
    相关资源
    最近更新 更多