我在Symfony2/Doctrine2中使用postPersist/postUpdate/postRemove事件。例如:學說2停止事件傳播
public function postPersist(LifecycleEventArgs $args){
}
我的問題是:如何阻止事件進一步傳播?
非常感謝
我在Symfony2/Doctrine2中使用postPersist/postUpdate/postRemove事件。例如:學說2停止事件傳播
public function postPersist(LifecycleEventArgs $args){
}
我的問題是:如何阻止事件進一步傳播?
非常感謝
看起來像你不能這樣做。看看UnitOfWork :: executeInserts方法和EventManager :: dispatchEvent方法。 Ther沒有休息,沒有嘗試/抓住它。
您確定要這樣做嗎?這樣做可能會傷害你的項目。例如。 FOSUserBundle正在監聽此事件以更新用戶的信息。強制傳播停止可以破壞用戶登錄功能。
我認爲你是對的,沒有辦法阻止事件的傳播。現在的問題是我有一個無限循環。我將以其他方式解決這個問題。 – Ben
使用開關來捕獲第二個電話:** if($ this-> called)return; $ this-> called = true; // ... **或更短:** if(0 == $ this-> callCounter ++)return; // ... ** –
你想停止行動嗎?即不堅持? –