Hi,
I'm having some problems with my Micro app. The documentation states:
"An instantiated controller automatically acts as a listener for dispatch events, so you can implement methods as callbacks:"
However, when I implement that function into my controller, it does not get called. Is this a limitation of the micro app or am I doing something wrong?
Controller function:
/**
* Changed output to valid JSON
* @param \Phalcon\Mvc\Dispatcher $dispatcher
*/
public function afterExecuteRoute(\Phalcon\Mvc\Dispatcher $dispatcher)
{
echo "test";
die();
$this->response->setContentType('application/json', 'UTF-8');
$data = $dispatcher->getReturnedValue();
if (is_array($data))
{
$this->response->setJsonContent($data);
}
else
{
$this->response->setStatusCode(500, "Internal Server Error");
$this->response->setJsonContent(array("status" => "ERROR"));
}
$this->response->send();
}
To setup my dispatcher in the Micro bootstrap file:
//Setup dispatcher
$di->set('dispatcher', function(){
//Create an event manager
$eventsManager = new EventsManager();
$dispatcher = new MvcDispatcher();
//Bind the eventsManager to the view component
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
}, true);