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.


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();

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

  • I tried this with the event checkout_cart_product_add_after and both the $observer->getEventName() and $event->getEventName() returned null Oct 16 '13 at 7:07
  • Please update the question with your code so we can take a look
    – Sander Mangel
    Oct 16 '13 at 7:12
  • it was not my question ;) but i simply did a var_dump on the event object, which had information but just not the event name. I wonder if this only works for some events as the one I checked with is called via Mage::dispatchEvent('checkout_cart_product_add_after', array('quote_item' => $result, 'product' => $product)); Oct 16 '13 at 7:14
  • -.- ok in my defence, it's quite early here... Thanks for the feedback, let me check into this!
    – Sander Mangel
    Oct 16 '13 at 7:16
  • 1
    From what I see in the Varien_Event_Observer class it shouldn't. oh well, we'll just file this under one of those wonderfull mysteries that make Magento so exciting to work with I guess ;)
    – Sander Mangel
    Oct 16 '13 at 7:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.