Is there a comprehensive list of observer events?

雨燕双飞 提交于 2020-01-14 03:58:30

问题


Is there a comprehensive list of all events that can be listened for?

If this list doesn't exist, what's the best method to debug to obtain all events?


回答1:


You'll never find a complete list. But if you go to app/Mage.php you can put in some debug code inside of the function "dispatchEvent()" and log all of the events as you go.

$params = array();
foreach (array_keys($data) as $key) {
    if (is_object($data[$key])) {
        $params[] = $key.' ('.get_class($data[$key]).')';
    } else {
        $params[] = $key.' ('.gettype($data[$key]).')';
    }
}
Mage::log('event_name:'.$name.',event_passed_keys:'.implode('|',$params),null,'events.log',true);

Then using some excel wizardry you can parse those out into a list of all of the event names and parameters being passed to it.

The problem with many of the compiled lists or even doing the grep as shown above is that many of the events are dynamically created. Which lets you discern what events there are that aren't listed.

Make sure to comment out that debug code or the events.log file will become huge after just a short time.




回答2:


Take a look at a list of events @

  • http://www.nicksays.co.uk/magento_events_cheat_sheet/

  • Customize Magento using Event/Observer

or

To log all the event for a specific page in your dev environment you could add Mage::log($eventName);

in /app/code/core/Mage/Core/Model/App.php

public function dispatchEvent($eventName, $args){
    Mage::log($eventName); 
    ....

or

grep -r Mage::dispatchEvent /path/to/your/Magento/* > events.txt

Read more @

  • Magento which event is called? Need to build an observer

  • https://magento.stackexchange.com/questions/153/where-can-i-find-a-complete-list-of-magento-events




回答3:


As an exercise I wrote a Bash script to generate rough list of events (it actually acts as a wrapper to grep with a few switches to provide context and available params).

I've used this script to generate events lists for default Magento installations for versions 1.3.3.0 to 1.8.0.0 version and the code is available at GitHub:

https://github.com/Marko-M/magento-events-list/

Lists of events are available here:

https://github.com/Marko-M/magento-events-list/tree/master/magento-outofthebox

and a follow up article on my blog here:

http://www.techytalk.info/bash-script-to-generate-list-of-events-for-magento-installation/

Be aware that these lists can never be complete due to many event names being generated dynamically.

As you probably have extensions on your project and they dispatch their own events, it's even better to generate this list manually trough grep or using my script.

Cheers!




回答4:


a general mean is to set an observer for any specific event you are interesting in

see https://magento.stackexchange.com/questions/314/how-to-know-the-magento-event-that-we-want-to-hook

in the module Logevent, the config.xml

0.1

Maticode_Logevent_Model

<controller_action_predispatch>
    <observers>
        <Logevent>
            <type>singleton</type>
            <class>Logevent/observer</class>
            <method>controller_action_predispatch</method>
        </Logevent>
    </observers>
</controller_action_predispatch>

and the Model/observer.php

    <?php

class Maticode_Logevent_Model_Observer { public function controller_action_predispatch($observer) { Mage::log ( $observer->getEvent ()->getControllerAction ()->getFullActionName (),null, 'eventlog.log' ); }

}

This way , in the

var/log/eventlog.log file  

u can visualize a possible hook on any tested actions (click on a button and check your log )



来源:https://stackoverflow.com/questions/13237400/is-there-a-comprehensive-list-of-observer-events

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!