嗨我想創建在我的包中做什麼的日誌。所以我正在使用Symfony2的OnFlush事件。併爲此創建了一個Listener。但它沒有被觸發。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」方法。請指導我在這裏失蹤。
感謝提前
請嘗試'退出(轉儲(「保存數據後來到這裏)))'。 – Alsatian
仍然無法正常工作。它似乎控制不去那裏 –
你的config.xml文件在哪裏?你清除了緩存嗎? – Alsatian