你需要一个事件订阅者而不是一个事件监听器。 你可以将service标签改为doctrine.event_subscriber,你的类应该实现Doctrine\Common\EventSubscriber。你需要定义一个getSubscribedEvents来满足EventSubscriber,它返回一个你想要订阅的事件数组。 ex
<?php
namespace Company\YourBundle\Listener;
use Doctrine\Common\EventArgs;
use Doctrine\Common\EventSubscriber;
class YourListener implements EventSubscriber
{
public function getSubscribedEvents()
{
return array('prePersist', 'onFlush');
}
public function prePersist(EventArgs $args)
{
}
public function onFlush(EventArgs $args)
{
}
}
Acme\SearchBundle\Listener\SearchIndexer:
tags:
-
{
name: 'doctrine.event_listener',
# this is the only required option for the lifecycle listener tag
event: 'postPersist',
# listeners can define their priority in case multiple subscribers or listeners are associated
# to the same event (default priority = 0; higher numbers = listener is run earlier)
priority: 500,
# you can also restrict listeners to a specific Doctrine connection
connection: 'default'
}
- {
name: 'doctrine.event_listener',
# this is the only required option for the lifecycle listener tag
event: 'postUpdate',
# listeners can define their priority in case multiple subscribers or listeners are associated
# to the same event (default priority = 0; higher numbers = listener is run earlier)
priority: 500,
# you can also restrict listeners to a specific Doctrine connection
connection: 'default'
}
3条答案
按热度按时间7gcisfzg1#
我认为你可以这样做:
zpqajqem2#
你需要一个事件订阅者而不是一个事件监听器。
你可以将service标签改为
doctrine.event_subscriber
,你的类应该实现Doctrine\Common\EventSubscriber
。你需要定义一个getSubscribedEvents
来满足EventSubscriber
,它返回一个你想要订阅的事件数组。ex
cgvd09ve3#
从Symfony 6.3开始,不推荐使用订阅服务器。因此,您可以使用以下内容: