How to generate an event in Magento 2

Here I will show you how to generate an event in your extension for Magento 2

  • This guide is very easy to do, so follow these simple steps
  • The following examples:
<?php

..

$event_data_array  =  ['cid' => '123'];

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$eventManager = $objectManager->create(‘\Magento\Framework\Event\Manager’);

$this->_eventManager->dispatch('my_custom_event', $event_data_array);

..

?>

As you can observe it’s quite simple to dispatch the event from almost anywhere in Magento. The first argument of the sending method is the name of the event and the second argument is used to send data to viewers.

Last Update: April 5, 2018  

February 28, 2018   226   Nandini R    Magento2    
Total 1 Votes:
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook
Twitter
INSTAGRAM
LinkedIn