Symfony 5 getDoctrine->getRepository() Invalid argument supplied for foreach() Doctrine CachedReader.php

Viewed 557

Friends, there was a problem that I cannot solve. Doing as per Symfony 5 documentation throws an exception: Invalid argument specified for foreach (). The stack trace points to vendor / doctrine / annotations / lib / Doctrine / Common / Annotations / CachedReader.php: 107. And essentially it doesn't let me access the repository in the controller. Resetting the entire Symfony cache helps for one request, then again the Exception is repeated. Tried accesses directory accesses with cache, did not help. I will be glad to the decision.

Entity:

/**
 * @ORM\Entity(repositoryClass=AuthorRepository::class)
 */
class Author
{
    /**
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     * @ORM\Column(type="integer")
     */
    private $id;

    // ...
}

Repository:

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

Controller:

class AuthorController extends AbstractController
{
    /**
     * @Route("/author/create", name="author-create")
     * Method ({"GET", "POST"})
     */
    public function actionCreate(Request $request, ValidatorInterface $validator): Response
    {
        // throw ErrorException !!!
        $repository = $this->getDoctrine()->getRepository(Author::class);
    }
  
    // ...
 }

method show Exception

Stack Trace

where the exception is throw

1 Answers
Related