类型Doctrine \ Bundle \ DoctrineBundle \ registry的对象是不可呼应的

发布于 2025-02-09 00:07:59 字数 470 浏览 2 评论 0 原文

尝试使用学说时,我有一个错误。

这是我的错误: 类型学说的对象\ bundle \ doctrineBundle \ registry不可召唤

,我的控制器:

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

      

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

有人可以帮助我吗?谢谢 :)

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 :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温柔一刀 2025-02-16 00:07:59

这可以在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
       ]);
    }

您可以在

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文