在magento中找不到新创建的Block类

时间:2016-12-28 13:36:44

标签: magento magento-1.9.2.4

突然在Magento 1.9.2.4中,我无法创建新的块。意思是当我创建类文件和前端时,当我尝试获取类名或获取布局时,表示找不到类。

现有块正常工作,只有新块无效。

我在config xml中定义了块

<?xml version="1.0"?>
<config>
  <modules>
    <Custom_Homepage>
      <version>0.1.0</version>
    </Custom_Homepage>
  </modules>
  <global>
    <blocks>
      <homepage>
        <class>Custom_Homepage_Block</class>
      </homepage>
    </blocks>
  </global>
</config>

<?php
 class Custom_Homepage_Block_Product_Slider3 extends
       Mage_Catalog_Block_Product_List{
   protected function _construct(){
      echo 1212;exit;
   }
 }
 ?>

尝试在模板文件中调用块: -

$this->getLayout()->createBlock('homepage/product_Slider3')
->setTemplate('homepage/catalog/product/category-3.phtml')->toHtml();

2 个答案:

答案 0 :(得分:0)

尝试使用Mage_Core_Block_Template而不是Mage_Catalog_Block_Product_List进行扩展。也改变这个

app.controller("AerodynamicCtrl", ["$scope", "$localStorage", "$fileLogger", AerodynamicCtrl]);

function AerodynamicCtrl($scope, $localStorage, $fileLogger){

    $scope.init_aerodynamic_activity = function(){

        if($scope.question_info.category == 1){
            $('.spritespin').spritespin({
                // generate an array of image urls. This is a helper function that takes a {frame} placeholder
                source: SpriteSpin.sourceArray('img/aero/{frame}.png', {
                    frame: [1,52] // this ramge of numbers is interpolated into the {frame} placeholder
                }),
                width: 480, // Specify the display width and height of the frame. // Optionally the size of the container can be defined with CSS.
                height: 327,
                responsive: true
            });

        } else {
            $('.spritespin').spritespin({
                // source: 'lib/threesixty-slider/assets/panorama.jpg',
                source: 'img/aero/panorama.jpg',
                width: 600, // this sets the width of the display. The panorama image must be larger than the below width
                height: 300,
                // select the modules
                mods: [
                    'drag',  // change frame on mouse drag
                    'ease',  // enable the easing module. this will ease out the animation after mouse release, instead of a hard stop
                    'panorama' // the panorama display module
                ]
            });
        }
    }
}

$this->getLayout()->createBlock('homepage/product_Slider3') ->setTemplate('homepage/catalog/product/category-3.phtml')->‌​toHtml(); 

要显示此块内容,您也可以这样调用,因为您没有使用任何前端布局

$this->getLayout()->createBlock('homepage/product_slider3') ->setTemplate('homepage/catalog/product/category-3.phtml')->‌​toHtml(); 

答案 1 :(得分:0)

除了Jickson提到的块名称中的拼写错误之外 - 您永远不应该在模板中以编程方式创建块。相反,使用Layout XML将块添加到需要调用它的块中。然后,在该块的模板文件中使用$this->getChildHtml()来调用您的新块。

手动创建它实际上绕过了框架,这违背了使用它的目的。