Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Magento中正确加载块?_Php_Magento_Module - Fatal编程技术网

Php 如何在Magento中正确加载块?

Php 如何在Magento中正确加载块?,php,magento,module,Php,Magento,Module,我在创建模块时遇到了问题。目标很简单,在我的模块中添加一个块 我知道xml文件应该加载,因为强制加载时会显示错误 模块配置: <modules> <Cardfever_Product> <version>0.1.0</version> </Cardfever_Product> </modules> 最后是我的代码块: class Cardfever_Product_Block_Confir

我在创建模块时遇到了问题。目标很简单,在我的模块中添加一个块

我知道xml文件应该加载,因为强制加载时会显示错误

模块配置:

<modules>
    <Cardfever_Product>
        <version>0.1.0</version>
    </Cardfever_Product>
</modules>
最后是我的代码块:

 class Cardfever_Product_Block_Confirm extends Mage_Core_Block_Template
 {
     public function methodblock()
     {
          return 'informations about my block !!' ;
     }
 }
希望有人能帮助我

在布局中使用

<block type="cardfever_product/confirm" name="productadd" template="product/confirm.phtml" />

并且必须在块中使用
toHtml()
方法,而不是methodblock()。或者通过
$this->methodblock()在模板内调用方法
product/confirm.phtml
<?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 !!' ;
     }
 }
<block type="cardfever_product/confirm" name="productadd" template="product/confirm.phtml" />