The Mage_Core_Controller_Varien_Front is instantiated. This is the class which is always used despite its front name. It picks which routers should be used.
Mage_Core_Controller_Varien_Front → dispatch() → Router Match Loop. The standard routers are:
- Mage_Core_Controller_Varien_Router_Standard (Frontend)
- Mage_Core_Controller_Varien_Router_Admin (Admin)
- Mage_Core_Controller_Varien_Router_Default (Default)
When a router matches in the loop, its job is to set the following on the request:
And then calls dispatch on the instance of the controller (Eg. Mage_Cms_IndexController).
Dispatch is defined in Mage_Core_Controller_Varien_Action, which is extended by Mage_Core_Controller_Front_Action, which should be extended by custom controllers on the frontend.
The dispatch method calls predispatch in the controller. To not dispatch the controller, I.e to forward to another controller at this point, set:
And the controller’s action method will not be called. To switch controller, action, etc, change the values on the request object, and the router’s match loop will continue and attempt to dispatch the new controller. The predispatch method then fires:
Event: controller_action_predispatch_ + getRouteName()
Event: controller_action_predispatch_ + getFullActionName()
These events can also be used to hook into, and forward to another controller if required. At this point, no blocks are created – the layout cannot be manipulated. If the request’s isDispatched method, remains as true, then the flow continues, and the controller’s action method is executed.
The following two methods (loadLayout and renderLayout) must be called from the custom controller’s action method for these to apply
is called with the option to supply handles. These replace the ‘default’ handle, so if using this, pass default in your handles array. Note: These handles will be added before any action layout handles, so the instructions within them may be overwritten.
adds the STORE_code layout handle, theme handle (THEME_*), and the full action name in lowercase (E.g. customer_account_index)
This is the best event to use to add custom layout handles, however it will fire for every controller. See this for workarounds.
The XML has been generated at this point, not any actual layout blocks. If required, modifications to the XML could be made at this point.
The blocks are now created. Each block fires:
before the block’s _prepareLayout() is called, followed by
This is where blocks can programatically be inserted into the layout.
Event: controller_action_layout_render_before_ + fullActionName
where blocks can also be added to the layout programatically, however a reference to the layout object is not passed in the dispatchd observer, so the layout must be retrieved using Mage::app()->getLayout()
The controller’s postDispatch() method is then called, firing the following events:
Event: controller_action_postdispatch_ + $this->getFullActionName()
Event: controller_action_postdispatch_ + $this->getRouteName()