我创建一个订阅者并注册一个新服务,我做什么: https ://gist.github.com/Draeli/2c591c16409a5664ae58
<?php
namespace My\BlogBundle\Listener;
use Doctrine\ORM\Events;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
class BlogArticleDetailListener implements EventSubscriberInterface
{
/**
* @var ContainerInterface
*/
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
static public function getSubscribedEvents()
{
return array(
'doctrine.event_subscriber' => array(
array(Events::prePersist, 0),
array(Events::preUpdate, 0),
),
);
}
public function prePersist(FilterResponseEvent $event)
{
var_dump('prePersist');die;
}
public function preUpdate(FilterResponseEvent $event)
{
var_dump('preUpdate');die;
}
}
services:
my_blog.listener.blog_article_detail:
class: My\BlogBundle\Listener\BlogArticleDetailListener
arguments: ["@service_container"]
tags:
- { name: kernel.event_subscriber }
但在这种情况下,方法 prePersist 和 preUpdate 尽管我持久化了对象,就像 Doctrine 没有调度一样。有人知道我做什么强吗?
(为了解释,现在我只注册教义事件,但之后我会从同一个地方注册更多)