【发布时间】:2015-02-02 16:36:14
【问题描述】:
我是 Phalcon 的新手,我正在尝试将侦听器绑定到调度程序服务。
这是监听器:
<?php
namespace Core\Listener;
use Phalcon\DI;
use Phalcon\Dispatcher;
use Phalcon\Events\Event;
use Phalcon\Mvc\User\Plugin;
class DispatchListener extends Plugin
{
protected $_logger;
public function __construct()
{
$this->_logger = new \Phalcon\Logger\Adapter\File( 'logs/app.log' );
}
public function beforeDispatch ( Event $event , Dispatcher $dispatcher )
{
$this->_logger->info( 'dispatching' );
}
public function afterDispatch ( Event $event , Dispatcher $dispatcher )
{
$this->_logger->info( 'dispatched....' );
}
}
还没有发生太多事情,只是在尝试设置。在我的引导 index.php 中,我有:
$di = new \Phalcon\DI\FactoryDefault();
$di->set('dispatcher', function() use ($di) {
//Obtain the standard eventsManager from the DI
$eventsManager = $di->getShared('eventsManager');
//Instantiate the Security plugin
$listener = new \Core\Listener\DispatchListener($di);
//Listen for events produced in the dispatcher using the Security plugin
$eventsManager->attach('dispatch', $listener);
$dispatcher = $di->getShared( 'dispatcher' );
//Bind the EventsManager to the Dispatcher
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});
现在,当我打开网站时,监听器没有任何反应。没有记录,什么都没有。我一定在这里忽略了一些明显的东西,但我看不到什么。
【问题讨论】:
标签: phalcon