OnFlush无法运行Symfony2 ODM

时间:2016-07-05 05:59:01

标签: php mongodb symfony

您好我想创建在我的Bundle中做了什么的日志。所以我正在使用Symfony2的OnFlush事件。并为此创建了一个监听器。但它没有被触发。

//我的听众

namespace Edu\AccountBundle\EventListener;
use Doctrine\ODM\MongoDB\DocumentManager;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Bundle\FrameworkBundle\Routing\Router;
use Edu\AccountBundle\CommonFunctions\CommonFunctions;
use Edu\AccountBundle\Constants\allConstants;
use Symfony\Component\HttpFoundation\Session\Session;
use Doctrine\Common\EventSubscriber;
use Doctrine\ODM\Event\OnFlushEventArgs;

class OnFlushListener
{
    private $session;
    private $router;
    private $commonFunctions;
    private $constants;

    public function __construct(Session $session, Router $router, DocumentManager $dm)
    {
        $this->session = $session;
        $this->router = $router;
        $this->dm = $dm;
        $this->commonFunctions  = new CommonFunctions();
        $this->constants        = new allConstants();
    }

    public function onFlush(OnFlushEventArgs $event)
    {
        echo "come here after Saving data";die;
    }
} 

// config.xml中

<service id="edu.account.event.listener" class="Edu\AccountBundle\EventListener\OnFlushListener">
    <argument type="service" id="session"/>
    <argument type="service" id="router"/>
    <argument type="service" id="doctrine_mongodb.odm.document_manager"/>
    <tag name="doctrine.event_listener" event = "onFlush" method="onFlush"/>
</service>

当我试图保存任何文档时,它不会被调用。 “onFlush”方法。请指导我在此遗漏的内容。

谢谢你提前

1 个答案:

答案 0 :(得分:0)

您的服务代码名称错误,应为doctrine_mongodb.odm.event_listener。有关详细信息,请参阅http://my.device.com/?appdev=1