Certificated magento

3.17) Which class is responsible for creating an instance of the block?

In Magento, the whole block hierarchy during a page generation is created by the class Mage_Core_Model_Layout. The method generateBlocks is responsible of that. Let’s take a look…


public function generateBlocks($parent=null) {
    if (empty($parent)) {
        $parent = $this->getNode();
    // This loop iterates through each block defined in the layout update 
    // for the page being generated
    foreach ($parent as $node) {
        $attributes = $node->attributes();
        // Ignore flag is set for a block by calling the action remove
        // in a layout file
        if ((bool)$attributes->ignore) {
        // Here we can see main tags in a layout XML. We have: 
        // - <blocks /> which generate a new block. 
        // - <reference /> which allows to reference to a pre-existing block. 
        // - <action /> which executes some action in a block.
       switch ($node->getName()) { 
           case 'block':
               $this->_generateBlock($node, $parent);
           case 'reference':
           case 'action':
               $this->_generateAction($node, $parent);
Three main tags are possible in a Magento layout file:
<block /> creates a new instance of a block.
<reference /> allows to reference a previously created (i.e. by another module) to execute some action on it.
<action /> allows executing some method of the block being referenced.

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...