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」をクラス名に変換するAimIT_ManufacturerBlock_Block_Manufacturerblockと、ブロックのクラス名が実際には「AimIT_ManufacturerBlock_Block_ManufacturerBlock」であるため、Magento が生成し、そのような名前でクラスを見つけることができません。これは大文字と小文字が間違っています。

クラスの名前をに変更します

class AimIT_ManufacturerBlock_Block_Manufacturerblock extends Mage_Core_Block_Template 
{

クラスファイルの名前をManufacturerBlock.php に変更しますManufacturerblock.php

于 2013-02-02T15:03:45.493 に答える