开发者

What's the earliest event Magento dispatches?

I need to fire off an 开发者_开发知识库event, as early as possible in the dispatch process, when a customer visits a frontend controller. The request is to be analysed and will, potentially, be redirected to a different URL, justifying the "as early as possible" requirement.

What's the earliest event a developer can subscribe to?


The earliest event I'd rely on is

controller_front_init_before 

The Magento front controller object (distinct from the the "index.php front controller") is the object that managers the routers, which in turn manages the action controller dispatch.

There's a few others (resource_get_tablename, core_collection_abstract_load_before, core_collection_abstract_load_after) that fire before, but they're more of the side effect variety (Magento using it's own systems to bootstrap itself) than anything you'd want to rely on.

Finally, as should always be pointed out, if you do a little logging in app/Mage.php

public static function dispatchEvent($name, array $data = array())
{
    file_put_contents('/tmp/events.log',"$name \n",FILE_APPEND);
    Varien_Profiler::start('DISPATCH EVENT:'.$name);
    $result = self::app()->dispatchEvent($name, $data);
    #$result = self::registry('events')->dispatch($name, $data);
    Varien_Profiler::stop('DISPATCH EVENT:'.$name);
    return $result;
}

patterns begin to emerge.


You are probably looking for controller_action_predispatch event.

There are a bunch of other events fired before it, but in this case I am assuming you still want to access the dispatched action controller.

If you want it even earlier, then your best bet would be controller_front_init_before, which is fired before the front controller is initialized.


Here is a list of events in Magento 1.4.1.1 and 1.5.1.0

There is also an event for each of the controller_action_predispatch and controller_action_postdispatch. To know which actions are being called you can add the following line

Mage::log('controller_action_predispatch_'.$this->getFullActionName());

to the preDispatch function of app/code/core/Mage/Core/Controller/Varien/Action.php

A similar line can be added to postDispatch function in the same file.


After some sluething it seems that - in terms of Magento EE Full Page Cache being enabled - the only reliable event you can listen for is http_response_send_before.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜