2016-07-05 5 views
-2

こんにちは私のバンドルで何をしたのかを作成したい。だから私はSymFony2のOnFlushイベントを使用しています。このためのリスナーを作成しました。それは引き起こされません。OnFlushが動作しないSymfony2 ODM

//マイリスナー

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"メソッド。私はこれに欠けているものを案内してください。

おかげアドバンス

+0

exit(ダンプ(「データを保存した後はここに来てください)」)を試してください。 – Alsatian

+0

まだ動作していません。それはコントロールがそこに行くと思わない –

+0

あなたのconfig.xmlファイルはどこですか?キャッシュをクリアしましたか? – Alsatian

答えて

0

サービスタグの名前が間違っている、それはdoctrine_mongodb.odm.event_listenerをする必要があります。詳細はdocsをご覧ください。

+0

は –

+0

は今、このエラーを与える..私はこの1つを試してみましょうしない: ServiceCircularReferenceException:「doctrine_mongodb.odm.default_document_manager」サービスのために検出された循環参照、パス:「doctrine_mongodb.odm.default_document_manager - > doctrine_mongodb.odm.default_connection - > doctrine_mongodb.odm.event_manager - > edu.account.event.listener」。 –

+0

はあなたのサービスに 'DocumentManager'を注入しないでください、あなたは私が私のメソッドの内部Doucment名を取得する方法をあなたの方法 – malarzm

関連する問題