我尝试在Magento中创建一个新的自定义模块(块),它将在产品详细信息页面上显示制造商提供的其他产品。当我加载产品详细信息页面时,我得到:
Fatal error: Class 'AimIT_ManufacturerBlock_Block_Manufacturerblock' not found in ..\app\code\core\Mage\Core\Model\Layout.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)\应用\设计\前端\默认\响应\模板\ 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(); ?>
创建模块时我省略了什么?
答案 0 :(得分: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