php - Cannot attach Events in module init()-method -


I have read about some of the best practices for ZF2. There, MIT was explained to engage incidents in () - Method of module module class:

  class module {public function getAutoloaderConfig () {Returns array ('Zend' Loader \ ClassMapAutoloader = '> Array (__DIR__.' /autoload_classmap.php ',),); } Public function init (ModuleManager $ moduleManager) {echo 'init & lt; Br> & # 39; & # 39; $ Em = $ Module Manager- & gt; GetEventManager (); $ Em- & gt; Attached (MvcEvent :: EVENT_DISPATCH, array ($ this, 'onDispatch')); $ Em- & gt; Attached (MvcEvent :: EVENT_ROUTE, array ($ this, 'onRoute')); } Public Function on Dispatches (MvcEvent $ e) {echo 'onDispatch & lt; Br> & # 39; & # 39; } ...  

No error is available, good but event has not caught ...

Any thoughts? I also tried the Shared Manager, but it only worked for EVENT_DISPATCH ...

Specific cases For, it is better to register your events for "initial events" for onBootstrap

init .

I have found a link that is quite clear:

You can get the Zend \ ModuleManager \ Listener \ DefaultListenerAggregate :: attch :

 Order in the public can get the order of the default MVC event Function Attached (Event Manager Interface $ Events) {$ options = $ this- & gt; GetOptions (); $ ConfigListener = $ this- & gt; GetConfigListener (); $ LocatorRegistrationListener = New Locator Registration Author ($ option); // High Priority, we believe that the module autoloading (for FooNamespace \ Module classes) is more than $$-> Audiences [] = $ events- & gt; Attach (new modular loader listener ($ option)) should be available; $ This- & gt; Listeners [] = $ event- & gt; Attach (module Avenue :: EVENT_LOAD_MODULE_RESOLVE, new moduleroller listener); // High Priority, because most other load modules will assume that the module's classes are available through $ autoloading $ -> gt; Listeners [] = $ event- & gt; Attach (module avenue :: EVENT_LOAD_MODULE, new AutoloaderListener ($ option), 9000); If ($ option-> getCheckDependencies ()) {$ this- & gt; Listeners [] = $ event- & gt; Attach (module document: EVENT_LOAD_MODULE, new module dependency checker listener, 8000); } $ This- & gt; Listeners [] = $ event- & gt; Attach (module Avenue :: EVENT_LOAD_MODULE, new InitTrigger ($ option)); $ This- & gt; Listeners [] = $ event- & gt; Attach (Module Avenue :: EVENT_LOAD_MODULE, New OnBootstrapListener ($ option)); $ This- & gt; Listeners [] = $ event- & gt; Attach ($ locatorRegistrationListener); $ This- & gt; Listeners [] = $ event- & gt; Attach ($ configListener); $ This return; }  

Comments