检测到服务“doctrine.dbal.default_connection”的循环引用,路径:“doctrine.dbal.default_connection”

问题描述 投票:1回答:2

当我试图将服务@doctrine.orm.entity_manager作为我的监听器UserDeletionListener的参数时发生错误。

我的服务:

se.doctrine_listener.user_deletion:
        class: SE\CoreBundle\DoctrineListener\UserDeletionListener
        arguments:
              - "@doctrine.orm.entity_manager"
        tags:
            - { name: doctrine.event_listener, event: preRemove }

我的听众:

namespace SE\CoreBundle\DoctrineListener;

use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Doctrine\ORM\EntityManager;
use SE\UserBundle\Entity\User;

class UserDeletionListener
{
    /**
     * @var \Doctrine\ORM\EntityManager
     */
    private $em;

    public function __construct(EntityManager $entityManager)
    {
        $this->em = $entityManager;
    }
/...

这是错误:

Circular reference detected for service "doctrine.dbal.default_connection", path: "doctrine.dbal.default_connection".
php symfony doctrine-orm doctrine
2个回答
2
投票

当你使用EventArgs {lifecycle,preUpdate等...]时,你不必再传递doctrine.orm.entity_manager :-D你可以通过eventArgs本身的方法getEntityManager来获取它


0
投票

将延迟加载添加到doctrine事件侦听器

* - {name:doctrine.event_listener,event:preRemove,lazy:true}

© www.soinside.com 2019 - 2024. All rights reserved.