You have experienced 7 steps of Request Follow topic and today, I will complete the Magento knowledge of this topic with Flushing Data article. As you may know, Flushing data is an important process in Magento. This function allows you to return browser the HTML code. It means that Flushing output is to display a content of a request in Magento. You can learn more with my following part.
1.Describe how and when Magento renders content to the browser.
– When there is a request from the browser, an action method in Controller is called.
– Layout Instance is initialized (usually in page.xml)
– Layout Update Instance runs, adding all updates to layout Instance.
– Output blocks are automatically rendered. All other blocks are only rendered when they are called by parent block:$this>getChildHtml(‘head’) . The process is described as below:
- Instances of the Layout and Layout Update are created.
- Layout handles are added according to the $handles argument if passed.
- Store layout handle STORE_[store_code] is added to the Layout Update Instance. For example, if the code of the current store is en, then layout handle STORE_en is added.
- Theme layout handle THEME_[area]_[package]_[layout_theme] is added to the Layout Update Instance. For example, if the page rendered is for the frontend area, the name of the current theme package is magebase and the theme name for layout is modern, then the layout handle THEME_frontend_magebase_modern is added.
- Action layout handle is added to the Layout Update Instance. For example, if the page rendered is a category detail page, then Magento is executing the view action of the catalog module’s category controller. So it will add an action handle that is catalog_category_view.
- All Layout XML files defined for all active modules are loaded.
- If a layout file named local.xml exists in the current theme’s layout folder, it is last loaded.
- Layout updates of all added layout handles from the loaded layout XML are merged
- Layout updates of all added layout handles from the database are merged
- If the $generateXML argument of loadLayout() method is passed as false, the initialization is finished.
- The layout update data is refined by removing all blocks and block references defined with the remove tag. (As discussed in Part 1)
- If $generateBlocks argument is passed as false, the initialization is finished.
- The instances of block classes are created according to the block definitions in the Layout XML.
- The methods are called with specified arguments on the blocks where action tags are defined.
2.Describe how and when Magento flushes output variables using Front_Controller.
In the function dispatch() of Front_Controller, we will see the code below:
… Varien_Profiler::start('mage::app::dispatch::send_response'); $this->getResponse()->sendResponse(); Varien_Profiler::stop('mage::app::dispatch::send_response'); …
This function will be called after the system selects controller and runs action corresponding to the request.
Command line $this->getResponse()->sendResponse(); will flush output variables to html for browser.
We hope you found this tip useful and over the next weeks we will be sharing more great practices and solutions to issues of Magento. Thanks for your following much 😉 !
Have a nice day.