Symfony2 postUpdate侦听器不起作用 [英] Symfony2 postUpdate listener not working
问题描述
我收到以下错误消息,
可捕获的致命错误:传递给Doctrine \ ORM \ Event \ PreUpdateEventArgs :: __ construct()的参数3必须为数组类型,给定null,在
Catchable fatal error: Argument 3 passed to Doctrine\ORM\Event\PreUpdateEventArgs::__construct() must be of the type array, null given, called in
,不知道从哪里开始解决这个问题.您可以在下面看到我的听众(简称)
and don't know where to start in solving this. You can see my listener (shortened) below
public function postUpdate(LifecycleEventArgs $args){
$entity = $args->getEntity();
$em = $args->getEntityManager();
$args->getEntityManager()->clear();
$securityContext = $this->container->get('security.context');
$token = $securityContext->getToken();
$userLoggedIn = $token->getUser();
if ($entity instanceof Activity) {
$em->flush();
}
}
有人有任何建议吗?
这是我在config中的服务部分
Here's my services section from config
activity.listener:
class: My\Bundle\EventListener\ActivityListener
arguments: ['@service_container']
tags:
- { name: doctrine.event_listener, event: prePersist }
- { name: doctrine.event_listener, event: postPersist }
- { name: doctrine.event_listener, event: postUpdate }
推荐答案
问题可能是由于postUpdate事件处理程序中的 $ em-> flush()
引起的,该更新稍后将触发 UnitOfWork :: executeUpdates
函数调用.
The problem is caused probably by the $em->flush()
inside the postUpdate event handler which later will trigger the UnitOfWork::executeUpdates
function call.
如果是这种情况,那么我发现的唯一解决方法是我在教义错误报告(尽管我不认为这是真正的教义错误).
If that's the case then the only workaround I've found is the one I documented in a Doctrine bug report (although I don't regard this as a true Doctrine bug).
这篇关于Symfony2 postUpdate侦听器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!