如何从phtml文件中调用块类函数


How to call block class function from phtml file

我有块类

    class GauravKhatri_BestSeller_Block_Index extends Mage_Core_Block_Template
{
public function getBestsellerProducts()
{       
//Here is my code
}
}

我有畅销书的.html文件。我想在phtml文件中得到该函数的结果。

有人能帮我怎么做吗?

如果这个模板文件"畅销书.phtml"与您的块直接关联。如以下示例:

<block type="bestSeller/index" name="bestseller" template="bestseller.phtml "/>  

则可以使用CCD_ 2访问关联模板中该块类CCD_。例如:

$this->getBestsellerProducts();

您可以直接调用模板中的块

$bestseller = $this->getLayout()->getBlock('bestSeller/index');
$bestseller->getBestsellerProducts();