When you read the class Mage_Core_Block_Abstract,you will know that magento creates a very powerful block system.
public functionsetChild($alias, $block)
if (is_string($block)) {
$block =$this->getLayout()->getBlock($block);
}
if (!$block) {
return$this;
}
$block->setParentBlock($this);
$block->setBlockAlias($alias);
$this->_children[$alias] =$block;
return $this;
}
<referencename="left">
<blocktype="directory/currency" name="currency"template="directory/currency.phtml"/>
</reference>
First of all, Mage_Core_Block_Abstract is thesubclass of Varien_Object. That is to say, magentospecific block class whose parent classis Mage_Core_Block_Abstract can add as many childblocks as possible and access them in the array-style
way.
{Moreover, Magento provides two ways to use block: XML layoutway and object way.
1.Use XML layout way
<catalog_category_default>
</catalog_category_default>
In the template file, use following statement<?php echo$this->getChildHtml("currency");?>
2.Object way
<?php
$currency =new Mage_Directory_Block_Currency();
echo $currency->toHtml();
?>
本文介绍了Magento中的块系统,包括Mage_Core_Block_Abstract类的功能及其继承自Varien_Object的特点。文章详细解释了如何通过XML布局文件及对象方式来创建和使用块,并提供了具体的代码示例。

被折叠的 条评论
为什么被折叠?



