I am wondering if there is an event that is fired once every time a page is loaded before rendering to html in magento?
This might be useful if you want to do some b
I think you are looking for this event controller_action_layout_render_before_RouteName_ControllerName_ActionName
you can also log all the events which are fired on any page load from Mage
class in below function
public static function dispatchEvent($name, array $data = array())
{
Mage::log($name);
Varien_Profiler::start('DISPATCH EVENT:'.$name);
$result = self::app()->dispatchEvent($name, $data);
Varien_Profiler::stop('DISPATCH EVENT:'.$name);
return $result;
}
We can use controller_front_init_routers event using observer. In that observer method,you can get request object as follows.
$request = $observer->getEvent()->getData('front')->getRequest();
http://www.nicksays.co.uk/magento-events-cheat-sheet-1-7/ this will help.
app/code/core/Mage/Core/Controller/Varien/Action.php
this event
controller_action_layout_load_before
is fired
app/code/core/Mage/Core/Block/Abstract.php
event
core_block_abstract_to_html_before
above two events might be of help.
There are several request-related events which are dispatched for most page-/content-generating requests. Below is a partial list in processing order of some useful ones, and I expect others may comment on this post with some others. Many of these are not suitable for your need (I've noted in bold below where you should begin considering). There are also a few block-instantiation-related events which, although they could be observed for your purpose, are generic to every block and really aren't appropriate.
The first practical singly-fired event is controller_front_init_before. This event is dispatched in Front Controller initialization in response to all dispatched requests. Because it is dispatched before the action controllers are invoked, only global-area observers will be able to observe this event.
Assuming the request is routed from the Front Controller through the routers to an action controller, there are some events which can be observed prior to rendering in preDispatch() - note the generic controller_action_predispatch
event handle which could be consumed for all events vs the two dynamic event handles:
Mage::dispatchEvent('controller_action_predispatch', array('controller_action' => $this));
Mage::dispatchEvent('controller_action_predispatch_' . $this->getRequest()->getRouteName(),
array('controller_action' => $this));
Mage::dispatchEvent('controller_action_predispatch_' . $this->getFullActionName(),
array('controller_action' => $this));
How a response is being rendered may affect the events available; the main variations would come from whether or not layout updates are being used to render the response (and how). For example, core_layout_update_updates_get_after could be used to inject a layout update file to the list of configured module layout update files (a rare but potentially useful case). The controller actions are closely coupled with the layout modeling, so there are a few events which could work:
Assuming that renderLayout()
is being used in all actions about which you care, there are two events (one generic and one route-specific) which it dispatches:
Mage::dispatchEvent('controller_action_layout_render_before');
Mage::dispatchEvent('controller_action_layout_render_before_'.$this->getFullActionName());
After all of the routing, dispatching, view configuring, block instantiating, and rendering are done, there is one last-ditch event which is dispatched by the Front Controller before the response is sent: controller_front_send_response_before. This event is not suitable for your need, but it's a nice bookend to the controller_front_init_before
event which began this answer.