2013-05-06 29 views
2

如何从Magento中的控制器调用块功能。Magento中的控制器内的呼叫块功能

我有波纹管控制器:

法师/结算/控制器/ CartController.php

我想打电话给在此CartController波纹管块功能

法师/结算/块/车/ Shipping.php

我该怎么做?

感谢

回答

-2

创建法师/结账/块/车/ Shipping.php这样简单getTest()函数。

public function getTest() 
{ 
    $data = 'test'; 
    return $data; 
} 

然后像这样在Mage/checkout/controllers/CartController.php文件中调用它。

echo $this->getTest(); 
+1

NOP..It给我胎儿的错误 – tinkesh 2013-05-06 13:37:46

9

您可以使用:

$block = Mage::app()->getLayout()->createBlock('checkout/cart_shipping'); 

获得该块。

5

嗨,你可以通过两种方式调用控制器块,下面检查:

$myblock = $this->getLayout()->getBlockSingleton('checkout/cart_shipping')->getYourfunctionname(); 

OR

$myblock = $this->getLayout()->createBlock('checkout/cart_shipping')->getYourfunctionname(); 
1

装入块控制器

$block = $this->getLayout()->createBlock('Mage_Core_Block_Template','checkout')->setTemplate('checkout/cart1.phtml'); 
$this->getLayout()->getBlock('content')->append($block);