Magento – How to get associated event name from observer

event-observermagento-1.7

Say I have an observer, and I want to get the name of the event that's associated with it. What's the proper way to get this string, if it's possible?

e.g. customer_save_after or controller_action_predispatch_customer_account_createpost, etc.

Best Answer

To get the name of the triggered event you can use the following code

class [Namespace]_[Module]_Model_Observer
{
   function myObserver(Varien_Event_Observer $observer)
   {
      $event = $observer->getEvent();
      var_dump($event->getName());
   }
}

to see what other data is in the Event object just call getData which will display all the stored data.

[...]
var_dump($event->getData());
[...]
Related Topic