title: How to use ZF2's EventManager over multiple classes (and modules)?
body: <p>I am having the following setup: In a controller I trigger an event and I want to attach multiple listeners to it at other places.</p>
  
  <p>Currently I have the following listener in my <strong>onBootstrap</strong>:</p>
  
  <pre><code>$e-&gt;getApplication()-&gt;getServiceManager()-&gt;get('EventManager')-&gt;attach('*', function($e) {
      var_dump($e-&gt;getName());
  });
  </code></pre>
  
  <p>The following piece of code as a <strong>factory</strong>:</p>
  
  <pre><code>'Application\Controller\Foo' =&gt; function(ControllerManager $cm) {
      $eventManager = $cm-&gt;getServiceLocator()-&gt;get('EventManager');
      $controller = new \Application\Controller\FooController();
      $controller-&gt;setEventManager($eventManager);
      return $controller;
  },
  </code></pre>
  
  <p>And finally the following trigger within my <strong>controller</strong>:</p>
  
  <pre><code>$this-&gt;getEventManager()-&gt;trigger('foo-finished', 'finishedAction', array(
      'obj' =&gt; $foo-&gt;someObject()
  ));
  </code></pre>
  
  <p>So it should both be the same <code>EventManager</code> as I receive it from the service locator and inject it into the controller. Still I get no output at all. I also tried using <code>$e-&gt;getApplication()-&gt;getEventManager()</code> when attaching to events, but this only gives me the ZF internal events.</p>
  
  <p>I read about the <code>SharedEventManager</code>, but I do not fully understand why I should pass a context. I tried it like this (which is as I understood it), but still no output.</p>
  
  <pre><code>$e-&gt;getApplication()-&gt;getServiceManager()-&gt;get('EventManager')
      -&gt;getSharedManager()
      -&gt;attach('finishedAction', '*', function() { ... });
  </code></pre>
  
  <p>So, what am I doing wrong? I just want to trigger events and catch them in possibly different modules, but it seems to be made so complicated...</p>