Magento:自定义模块错误(在Layout.php中找不到类)
我试图在Magento中创建一个新的自定义模块(块),它将在产品详细信息页面上显示制造商提供的其他产品。 当我加载产品详细信息页面时,我得到:
Fatal error: Class 'AimIT_ManufacturerBlock_Block_Manufacturerblock' not found in ..appcodecoreMageCoreModelLayout.php on line 491
我创造了:
1)应用等模块 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)程序设计前台 DEFAULT 响应模板 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(); ?>
创建模块时我省略了什么?
将'aimitmanufacturerblock / manufacturerblock'转换为类名称时,Magento会生成AimIT_ManufacturerBlock_Block_Manufacturerblock
,并且无法在该名称下找到类,因为您的块的类名实际上是'AimIT_ManufacturerBlock_Block_ManufacturerBlock' - 这是错误的。
重新命名你的课程
class AimIT_ManufacturerBlock_Block_Manufacturerblock extends Mage_Core_Block_Template
{
将您的类文件ManufacturerBlock
重命名为Manufacturerblock.php
上一篇: Magento: error for custom module (Class not found in Layout.php)
下一篇: How are action methods within Magento layout xml files intended to be used