Hi all, I'm getting a strange behaviour of the events manager that doesn't fire my event. That's my controller:
public function generatePdfAction($id = null) { $this->view->disable(); $eventsManager=$this->di->get('eventsmanager'); if($id) $params['id'] = $id; else throw new Exception("Error Processing Request. Confirm ID needed", 1); $eventsManager->fire("confirm:genPdf", $params); //debug die('stop debug'); $responses = $eventsManager->getResponses(); echo json_encode($responses); }
That's the plugin listener
use Phalcon\Events\Event; use Phalcon\Mvc\User\Plugin; use Phalcon\Di; use Phalcon\Di\FactoryDefault; class ConfirmEventQueue extends Plugin { protected $di, $queue, $logger; public function _construct(){ $this->di = \Phalcon\DI::getDefault(); $this->queue = $this->di->getQueue(); $formatter = new \Phalcon\Logger\Formatter\Line("[".date("Y-m-d H:i:s")."][" . HOSTNAME . "][%type%] %message%"); $this->logger = new \Phalcon\Logger\Adapter\File(LOG_PATH . "confirm/" . date('Y-m-d') . ".log"); $this->logger->setFormatter($formatter); $this->logger->info("### ConfirmEventQueue ###"); //debug line echo 'eventmanger'; } ..... public function genPdf(Event $event, $params = null) { //debug line echo "putted"; $this->queue->putInTube('genPdf',$params); } ..... }
This is how I attach the plugin as listener inside the Module startup:
$di->get('eventsmanager')->attach( "confirm", new \App\Frontend\Plugins\ConfirmEventQueue() );
The plugin is attached because it writes the log line 'eventmanger', but it seems not to fire confirm:genPdf event because "putted" is not printed. Anyone has got an idea of what I'm doing wrong?