gpt4 book ai didi

php - 尝试清除 Symfony 4 应用程序缓存时出现 "Cannot autowire service"异常

转载 作者:行者123 更新时间:2023-12-04 17:30:32 31 4
gpt4 key购买 nike

我在 Symfony 4 下有一个项目,当我尝试对我的项目进行 Composer 更新时出现此错误

     Executing script cache:clear 
Script cache:clear returned with error code 1[KO]
!!
!! In DefinitionErrorExceptionPass.php line 54:
!!

!! Cannot autowire service "App\Repository\ActeRepository": argument "$registry" of method "__construct()" references interface "Symfony\Br
!! idge\Doctrine\RegistryInterface" but no such service exists. Try changing the type-hint to "Doctrine\Persistence\ManagerRegistry" instea
!! d.

!!

!!
!!
Script @auto-scripts was called via post-install-cmd
[KO]
<?php

和 ActeRepository 是以下
namespace App\Repository;

use App\Entity\Acte;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;

/**
* @method Acte|null find($id, $lockMode = null, $lockVersion = null)
* @method Acte|null findOneBy(array $criteria, array $orderBy = null)
* @method Acte[] findAll()
* @method Acte[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class ActeRepository extends ServiceEntityRepository
{
public function __construct(RegistryInterface $registry)
{
parent::__construct($registry, Acte::class);
}

// /**
// * @return Acte[] Returns an array of Acte objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('a')
->andWhere('a.exampleField = :val')
->setParameter('val', $value)
->orderBy('a.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/

/*
public function findOneBySomeField($value): ?Acte
{
return $this->createQueryBuilder('a')
->andWhere('a.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}

我现在不知道问题出在哪里并且项目无法更新我也尝试删除 var 和供应商文件并清除 composer 和 Symfony 的缓存但出现同样的问题我现在不知道为什么我找到了多个建议的解决方案但是他们不工作?

最佳答案

构造函数应如下所示:

public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Acte::class);
}

添加使用语句:
use Doctrine\Common\Persistence\ManagerRegistry;

扩展类:
extends ServiceEntityRepository

关于php - 尝试清除 Symfony 4 应用程序缓存时出现 "Cannot autowire service"异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60166563/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com