Note that there are some explanatory texts on larger screens.

plurals
  1. POTriggering a new event and listening for it
    primarykey
    data
    text
    <p>I am following a book where it shows how to trigger a new event and start listening for it. The event is called channel-25 it just contains fictional data for testing. I put error_log to trap the events process so that i know its working. The event does get triggered but for some reason i cannot listen to it. Here is a copy of module.php</p> <p>I have commented the section to where i trigger the even and where i listen for it.</p> <pre><code>&lt;?php namespace Debug; use Zend\ModuleManager\Feature\AutoloaderProviderInterface; use Zend\Mvc\ModuleRouteListener; use Zend\ModuleManager\ModuleManager; use Zend\eventManager\Event; use Zend\Mvc\MvcEvent; use Zend\EventManager\EventManager; //manage events (create/listen for events) class Module implements AutoloaderProviderInterface { public function getAutoloaderConfig() { return array( 'Zend\Loader\StandardAutoloader' =&gt; array( 'namespaces' =&gt; array( __NAMESPACE__ =&gt; __DIR__ . '/src/' . __NAMESPACE__, ), ), ); } public function getConfig() { return include __DIR__ . '/config/module.config.php'; } public function init(ModuleManager $ModuleManager) { $eventManager = $ModuleManager-&gt;getEventManager(); $eventManager-&gt;attach('loadModules.post', array($this, 'loadedModulesInfo')); //create new event $event = new EventManager('channel-25'); $event-&gt;trigger('new song', null, array('artist' =&gt; 'Adele')); error_log('New Event Triggered'); } public function loadedModulesInfo(Event $event) { $moduleManager = $event-&gt;getTarget(); $loadedModules = $moduleManager-&gt;getLoadedModules(); error_log(var_export($loadedModules, true)); } public function onBootstrap(MvcEvent $event) { //Now i will be listening for my sample event $eventManager = $event-&gt;getApplication()-&gt;getEventManager(); $sharedEventManager = $eventManager-&gt;getSharedManager(); $sharedEventManager-&gt;attach('channel-25', 'new song', function(Event $event) { $artist = $event-&gt;getParam('artist'); error_log('Found the Event. The artist is: ' . $artist); }); } public function handleError(MvcEvent $event) { $controller = $event-&gt;getController(); $error = $event-&gt;getParam('error'); $exception = $event-&gt;getParam('exception'); $message = 'Error: ' . $error; if($exception instanceof \Exception) { $message .= ', Exception(' . $exception-&gt;getMessage() . '):' . $exception-&gt;getTraceAsString(); } error_log($message); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload