magento 开发 得到block的方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/terry_water/article/details/81745959

开发文档:https://devdocs.magento.com/guides/m1x/magefordev/mage-for-dev-4.html

1. 在controller部分直接通过createBlock()的方式,直接创建得到$block

public function indexAction()
{
//Get current layout state
$this->loadLayout();
 
$block = $this->getLayout()->createBlock(
'Mage_Core_Block_Template',
'my_block_name_here',
array('template' => 'activecodeline/developer.phtml')
);
 
$this->getLayout()->getBlock('content')->append($block);
 
//Release layout stream... lol... sounds fancy
$this->renderLayout();
}

2.然后通过getBlock得到content的block,然后通过append加入上面创建的block即可

3.通过getChild得到子block

猜你喜欢

转载自blog.csdn.net/terry_water/article/details/81745959