簡體   English   中英

我想在Zend Framework 1.11中使用Symfony EventDispatcher

[英]I want to use Symfony EventDispatcher in Zend Framework 1.11

我想(需要)在Zend Framework 1.11中使用Symfony EventDispatcher我將EventDispatcher加載到zf的Bootstrap中...

public function run()
    {
        require APPLICATION_PATH . 
                '/../library/Symfony/Component/EventDispatcher/EventDispatcher.php';
        $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();

        $dispatcher->dispatch("bootstrap.prerun", null);

        parent::run();

        $dispatcher->dispatch("bootstrap.postrun", null);

    }

我的問題是,如何在ZF控制器中使用它?

感謝您的任何幫助。 最好的祝福,

我之所以這樣回答,是因為我的問題是了解如何集成兩個框架,以便讓Symfony的EventDispatcher在我的所有ZF應用程序(包括模塊)上工作。

這是我的解決方案:在引導程序上。

public function run()
{
    $dispatcher = $this->getResource("Far_Resource_EventDispatcher");

    $dispatcher->dispatch("bootstrap.prerun", null);

    $listener = new DM_Service_StockListener();

    $dispatcher->addListener(
            "equipment.new", 
            array($listener, 'onEquipment') 
            );

    parent::run();

    $dispatcher->dispatch("bootstrap.postrun", null);

}

我為EventDispatcher創建了一個資源,以這種方式實例化該資源,該資源將由引導程序全局訪問,並且可以使用資源啟動。 資源代碼為:

class Far_Resource_EventDispatcher extends Zend_Application_Resource_ResourceAbstract
{
    private $_dispatcher = null;

    public function init()
    {
        if ($this->_dispatcher === null ) {
            require APPLICATION_PATH . 
                '/../library/Symfony/Component/EventDispatcher/EventDispatcher.php';

            $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
        } else {
            $dispatcher = $this->_dispatcher;
        }
        $this->getBootstrap()->eventDispatcher = $dispatcher;

        return $dispatcher;

    }
}

然后在application.ini中設置

pluginPaths.Far_Resource_EventDispatcher = APPLICATION_PATH "/../library/Far/Resource/EventDispatcher.php"
resources.Far_Resource_EventDispatcher = true;

我在如何創建資源時使用了此示例: http : //blog.madarco.net/327/how-to-make-your-own-zend-framework-resource-plugin/

我仍在進行這項工作,但看起來在第一次測試中運作良好...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM