Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding events to Laminas

I am trying to add event for Laminas Framework that will fire when \Laminas\Mvc\MvcEvent::EVENT_DISPATCH is triggered. But absolutelly nothing happends, like this triggers not exists. What am I doing wrong?

This is the code under the module\Application\src\Module.php:

use Laminas\ModuleManager\ModuleManager;
use Laminas\Mvc\MvcEvent;

class Module
{
    public function init(ModuleManager $moduleManager)
    {
        ini_set("display_errors", '1');
        $eventManager = $moduleManager->getEventManager();
        $eventManager->attach(MvcEvent::EVENT_DISPATCH, [$this, 'onDispatch']);
    }

    public function onDispatch(\Laminas\EventManager\Event $event)
    {
        var_dump('ok');die;
    }
}
like image 576
b4rt3kk Avatar asked Mar 09 '26 10:03

b4rt3kk


1 Answers

I think you need use another method in Module it's should be something like this:

use Laminas\Mvc\MvcEvent;

class Module
{
    public function onBootstrap(MvcEvent $event)
    {
        $application = $event->getApplication();
        $eventManager = $application->getEventManager();

        $eventManager->attach(MvcEvent::EVENT_DISPATCH, [$this, 'onDispatch']);
    }

    public function onDispatch(MvcEvent $event)
    {
        var_dump('ok');
        die;
    }
}

In this case it onBootstrap. Hope help you

like image 159
Dmitry Avatar answered Mar 12 '26 11:03

Dmitry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!