hi, I’ve been trying for weeks to get to know with event manager mechanism, although there are lots of documentation out there, I couldn’t work with it. I read your example but there are few things I can’t handle.
the case is I want to add a listener which reacts to MvcEvent::EVENT_RENDER, I mean I want to get to URL and output them automatically in view template.
this is my listener in NavigationListener.php :
namespace Blog\Events;
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\ListenerAggregateInterface;
use Zend\Mvc\MvcEvent;
class NavigationListener implements ListenerAggregateInterface
{
protected $listener;
public function attach(EventManagerInterface $events,$priority = 1){
$shared = $events->getSharedManager();
$shared->attach('Zend\Mvc\View\Console\DefaultRenderingStrategy',
MvcEvent::EVENT_RENDER,[$this,'addParams']
,1000);
//$this->listener[] = $events->attach(MvcEvent::EVENT_RENDER
// ,[$this,'addParams']
//,1000);
}
public function detach(EventManagerInterface $events){}
public function addParams(MvcEvent $event){
// Get request URI
$uri = $event->getResult()->getUri();
return $uri;
}
}
first of all, I know when we want to listen to a private Event we have to use shared event manager, is this particular event private?
second of all, is it a MUST to register this listener via onBootstrap() or init() methods?
I put this code in module.config.php of my module:
'service_manager' => [
'invokables'=>[
Events\NavigationListener::class => Events\NavigationListener::class,
]
],
'listeners'=> [
Events\NavigationListener::class,
],
how should I know what are MvcEvent::EVENT_RENDER parameters? what is the target of this event that is to set as Identifires(I used ‘Zend\Mvc\View\Console\DefaultRenderingStrategy’)?
how to get the return value in the listener method at the end?