0
我在創建模塊時遇到了麻煩。目標很簡單,爲我的模塊添加一個塊。如何在Magento中正確加載代碼塊?
我知道xml文件被加載,因爲它應該,因爲它顯示一個錯誤,如果我強制它。
模塊配置:
<modules>
<Cardfever_Product>
<version>0.1.0</version>
</Cardfever_Product>
</modules>
包括佈局:
<layout>
<updates>
<product>
<file>product.xml</file>
</product>
</updates>
</layout>
我的模型包括(內部全局)
<blocks>
<cardfever_product>
<class>Cardfever_Product_Block</class>
</cardfever_product>
</blocks>
我product.xml:
<?xml version="1.0"?>
<layout version="0.1.0">
<product_index_add>
<reference name="content">
<block type="product/confirm" name="productadd" template="product/confirm.phtml" />
</reference>
</product_index_add>
</layout>
控制器正在運行和設置正確的網址:產品/指數/加:
public function AddAction()
{
$this->loadLayout();
$this->renderLayout();
}
最後我塊代碼:
class Cardfever_Product_Block_Confirm extends Mage_Core_Block_Template
{
public function methodblock()
{
return 'informations about my block !!' ;
}
}
希望有人能幫助我!
,你必須使用'toHtml()'方法在你的塊不methodblock()。或者你可以通過'$ this-> methodblock();'在模板'product/confirm.phtml'中調用你的方法 –