hi,I’ve been trying to figure out how zend-eventManager would work throughout the zend-mvc. I try to get some parameters from my uri and output them as some info in my view. I have found that I should utilize eventManager component to add my params for more than once. I am up to use MvcEvent::EVENT_RENDER
as the event and I want to write an Event Listener to react against triggering the event.
my Listener is code below:
namespace Blog\Events;
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\ListenerAggregateInterface;
use Zend\Mvc\MvcEvent;
class Example implements ListenerAggregateInterface
{
protected $listener;
public function attach(EventManagerInterface $events,$priority = 1){
$sharedManager = $events->getSharedManager();
$this->listener[] = $sharedManager->attach(__NAMESPACE__
,MvcEvent::EVENT_RENDER
,[$this,'addParams']
,1000);
}
public function addParams(MvcEvent $event){
// Get request URI
$uri = $event->getRequest()->getUri();
echo $uri;
}
}
I already know I must register this Event Listener to module entry at Module.php in my Module, but I do NOT understand how it works with all provided explanation.
I acted like this in Module.php:
public function onBootstrap(MvcEvent $event)
{
$eventManager = $event->getApplication()->getEventManager();
$sharedEventManager = $eventManager->getSharedManager();
}
I’ve seen passing ModuleManager instances
and EventInterface and MvcEvent to the method but I have no ideat what the differences are!!!
Anyway,how should I keep going to work it out?!?!?!?!?
How should I register my Listener correctly?