1

我尝试在 Magento 中创建一个新的自定义模块(块),它将在产品详细信息页面上显示制造商的其他产品。当我加载产品详细信息页面时,我得到:

Fatal error: Class 'AimIT_ManufacturerBlock_Block_Manufacturerblock' not found in ..\app\code\core\Mage\Core\Model\Layout.php on line 491

我创造了:

1)\app\etc\modules\AimIT_ManufacturerBlock.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <modules>
    <AimIT_ManufacturerBlock>
      <!-- Whether our module is active: true or false -->
        <active>true</active>
        <!-- Which code pool to use: core, community or local -->
          <codePool>local</codePool>
        </AimIT_ManufacturerBlock>
      </modules>
    </config>

2) \app\code\local\AimIT\ManufacturerBlock\etc\config.xml

<?xml version="1.0"?>
<config>
  <global>
    <blocks>
      <aimitmanufacturerblock>
        <class>AimIT_ManufacturerBlock_Block</class>
      </aimitmanufacturerblock>
    </blocks>
  </global>
</config>

3) \app\code\local\AimIT\ManufacturerBlock\Block\Manufacturerblock.php

<?php
class AimIT_ManufacturerBlock_Block_Manufacturerblock extends Mage_Core_Block_Template 
{    
    public function getManufacturerProducts($manufacturer)
    {
        $collection = Mage::getModel('catalog/product')->getCollection();
        $collection->addAttributeToFilter('manufacturer',$manufacturer);
        $collection->addAttributeToSelect('manufacturer');

        return $collection;
    }
}
?>

4)\app\design\frontend\default\respond\template\aimit\manufacturerblock\manufacturerblock.phtml

<?php $_products = $this->getManufacturerProducts('cukrarna-u-vanku') ?>
<?php print_r($_products); ?>

5) 在 catalog\product\view.phtml 我放置了这段代码:

<?php echo $this->getLayout()->createBlock('aimitmanufacturerblock/manufacturerblock')->setTemplate('aimitmanufacturerblock/manufacturerblock.phtml')->toHtml(); ?>

创建模块时我省略了什么?

4

1 回答 1

2

将“aimitmanufacturerblock/manufacturerblock”翻译成 Magento 生成的类名AimIT_ManufacturerBlock_Block_Manufacturerblock时,找不到该名称下的类,因为您的块的类名实际上是“AimIT_ManufacturerBlock_Block_ManufacturerBlock”——大小写错误。

将您的课程重命名为

class AimIT_ManufacturerBlock_Block_Manufacturerblock extends Mage_Core_Block_Template 
{

将您的类文件ManufacturerBlock.php 重命名为Manufacturerblock.php

于 2013-02-02T15:03:45.493 回答