当我试图将服务@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".
当你使用EventArgs {lifecycle,preUpdate等...]时,你不必再传递doctrine.orm.entity_manager :-D你可以通过eventArgs本身的方法getEntityManager来获取它
将延迟加载添加到doctrine事件侦听器
* - {name:doctrine.event_listener,event:preRemove,lazy:true}