Magento: error for custom module (Class not found in Layout.php)

I tried to create a new custom module (block) in Magento which will show other products from manufacturer on product detail page. When I load product detail page I get:

Fatal error: Class 'AimIT_ManufacturerBlock_Block_Manufacturerblock' not found in ..appcodecoreMageCoreModelLayout.php on line 491

I have created:

1)appetcmodulesAimIT_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) appcodelocalAimITManufacturerBlocketcconfig.xml

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

3) appcodelocalAimITManufacturerBlockBlockManufacturerblock.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)appdesignfrontenddefaultrespondtemplateaimitmanufacturerblockmanufacturerblock.phtml

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

5) in catalogproductview.phtml I have placed this code:

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

What did I omit while creating the module?


When translating 'aimitmanufacturerblock/manufacturerblock' into a class name Magento generates AimIT_ManufacturerBlock_Block_Manufacturerblock and can't find a class under such name because your block's class name is actually 'AimIT_ManufacturerBlock_Block_ManufacturerBlock' - which is wrongly cased.

Rename your class into

class AimIT_ManufacturerBlock_Block_Manufacturerblock extends Mage_Core_Block_Template 
{

Rename your class file ManufacturerBlock .php into Manufacturerblock.php

链接地址: http://www.djcxy.com/p/59484.html

上一篇: Magento扩展在现有/核心页面添加和定位新块

下一篇: Magento:自定义模块错误(在Layout.php中找不到类)