Certificated magento

2.14) Describe how and when Magento renders content to the browser

First, let’s explain a few terms that are frequently used in this article:

MVC Action: MVC action is nothing but a method defined in a controller class and mapped with the requested URL. For example: when a category page is requested, the action method called is Mage_Catalog_CategoryController::viewAction().

MVC action methods perform the backend processing for the current requested page like retrieving and storing data from/to the database.

Layout Instance: Layout Instance is responsible for the page to be rendered. Before the page is rendered, Magento always creates a Layout Instance.

Layout Update Instance: While the Layout Instance is responsible for page rendering, the Layout Update Instance is responsible for all the updates to be added in the page layout once the layout instance has been created. This instance contains the data of all layout handles added to the current page.

Output Blocks: Output blocks are like normal blocks but they are directly involved with the response. When the layout is rendered, only the output blocks are rendered automatically. So it is output block’s responsibility to render its child blocks by calling a method like $this->getChildHtml(). For example, in the default theme, only the root block is an output block so at response time, only the root block is actually rendered but its phtml template calls methods like $this->getChildHtml('head') which renders its child blocks like the head block. So, output blocks are rendered automatically while other blocks are rendered if they are invoked by their parent blocks.

- 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 code of 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 current theme package name is magebase and 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 catalog module’s category controller’s view action. So it will add an action handle 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 loaded last
  • 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. (As discussed in Part 1)
 

http://magebase.com/magento-tutorials/digging-deeper-into-magentos-layout-xml-part-2/

0 Bình luận

Trở về
  • 1.12) Set up a cron job
  • 1.12) Set up a cron job

    Let’s start with server setup.   As any complex system, Magento has a lot of tasks that need to be executed...