Object of type Doctrine\Bundle\DoctrineBundle\Registry is not callable

Viewed 86

I've got an error when trying to use doctrine.

Here is my error: Object of type Doctrine\Bundle\DoctrineBundle\Registry is not callable

And my controller:

public function index(ManagerRegistry $doctrine): Response
    {
        $articles  = $doctrine()->getRepository(Article::class)->findAll();

      

        
        return $this->render('blog/index.html.twig', [
        'controller_name' => 'BlogController',
        'articles' => $articles,
    ]);
    }

Can someone help me ? thanks :)

1 Answers

This works on Symfony 5.4:

use Doctrine\Persistence\ManagerRegistry;
//...
public function index(ManagerRegistry $doctrine): Response
    {
    $articles  = $doctrine->getRepository(Article::class)->findAll();
    
    return $this->render('blog/index.html.twig', [
       'controller_name' => 'BlogController',
       'articles' => $articles
       ]);
    }

You can learn more in Symfony docs and Doctrine ORM docs.

Related