我使用Symfony的2.3奏鳴曲管理員捆綁與DoctrineExtensions(由StofDoctrineExtensionsBundle啓用)時。我啓用,配置併成功測試了SoftDeleteable和Timestampable組件。Symfony的例外註冊新學說事件訂閱者(SoftDeleteable)
現在,當我嘗試使用Symfony的服務標記添加另一種學說事件訂閱,它似乎在softdeleteable監聽器被禁用。
我的服務:
my.contact.listener.tag:
class: My\ContactBundle\EventListener\TagListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setTagManager, [ @fpn_tag.tag_manager ] ]
認購人:
namespace My\ContactBundle\EventListener;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
use DoctrineExtensions\Taggable\Taggable;
use FPN\TagBundle\Entity\TagManager;
class TagListener implements EventSubscriber
{
/**
* @var TagManager
*/
private $tagManager;
/**
* @param \FPN\TagBundle\Entity\TagManager $tagManager
*/
public function setTagManager($tagManager)
{
$this->tagManager = $tagManager;
}
/**
* Load tags for Taggable entities
*
* @param LifecycleEventArgs $args
*/
public function postLoad(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof Taggable) {
$this->tagManager->loadTagging($entity);
}
}
/**
* Save tags for Taggable entities
*
* @param LifecycleEventArgs $args
*/
public function preUpdate(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof Taggable) {
$this->tagManager->saveTagging($entity);
}
}
/**
* Save tags for Taggable entities
*
* @param LifecycleEventArgs $args
*/
public function prePersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof Taggable) {
$this->tagManager->saveTagging($entity);
}
}
public function getSubscribedEvents()
{
return array(
'prePersist',
'preUpdate',
'postLoad',
);
}
}
在每一個請求,我得到異常:
Listener "SoftDeleteableListener" was not added to the EventManager!
如果我禁用我的用戶,問題就消失了。如何啓用我的事件訂閱者並且也可以使用softdeleteable?
感謝您分享這些信息。在23小時內獎勵你。 – TautrimasPajarskas
哦,不要在'postLoad'中加載標籤。今天剛剛被這個咬傷了。因爲如果你正在做一個DQL查詢,'postLoad'將當實體水合,但在創建任何關聯,然後調用(見注[這裏](http://docs.doctrine-project.org/en/latest/reference /events.html#lifecycle-events)。所以,如果你'loadTagging'這裏,水化器會以某種方式失去一些必要的數據繼續填充其他協會。而且你會抓你的頭想知道爲什麼像我一樣。 –