私のアプリケーションでは、私は "users"を持っています。 1人のユーザーが複数の「アカウント」を持つことができますEventListenerは他のエンティティと無限ループを更新します
「アカウント」エンティティにリスナーがあります。
私のサービスでaccount_listener:
class: AppBundle\EventListener\AccountListener
arguments:
- '@service_container'
tags:
- {name: doctrine.event_listener, event: preUpdate}
、方法更新前::それはこのような「service.yml」ファイルで宣言され
がpublic function preUpdate(PreUpdateEventArgs $eventArgs)
{
$entity = $eventArgs->getEntity();
if (!$entity instanceof Account) {
return;
}
$this->container->get('notification_manager')->sendNotification();
}
sendNotificationをメソッドは、エンティティを作成しようとする関数を呼び出し「通知「
public function sendNotification()
{
$notification = new Notification();
$data = array(
'label' => 'Hello'
)
$form_notif = $this->formFactory->create(NotificationType::class, $notification, ['method' => 'POST']);
$form_notif->submit($data,($method === 'POST'));
if ($form_notif->isValid())
{
$this->em->persist($notification);
$this->em->flush();
} else {
return $form_notif;
}
return $notification;
}
問題: 通知が作成され、PHPはSTですされていません無限ループでうまくいく。これを防止するために
、私はsendNotificationをメソッドのbegginingでこれを追加しました:これにより
$eventManager = $this->em->getEventManager();
$eventManager->removeEventListener(['preUpdate'],$this->container->get('account_listener'));
を、それが動作します。しかし、私は良い方法があると思う。
私を助けることができますか?
おかげ