[英]Newly Created Block class not found in magento
Suddenly in Magento 1.9.2.4 , I am not able to create new block. 在Magento 1.9.2.4中,突然无法创建新块。 Means when I create class file and on frontend when I try to get class name or get layout its says class not found.
表示当我创建类文件时以及在试图获取类名或布局时在前端显示未找到类的信息。
Existing blocks are working properly and only new one are not working. 现有模块正常工作,只有新模块不工作。
I have defined block in config xml 我已经在配置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;
}
}
?>
And trying to call block in template file :- 并尝试在模板文件中调用块:-
$this->getLayout()->createBlock('homepage/product_Slider3')
->setTemplate('homepage/catalog/product/category-3.phtml')->toHtml();
Try extend with Mage_Core_Block_Template instead of Mage_Catalog_Block_Product_List. 尝试使用Mage_Core_Block_Template而不是Mage_Catalog_Block_Product_List进行扩展。 Also change this
也改变这个
$this->getLayout()->createBlock('homepage/product_Slider3') ->setTemplate('homepage/catalog/product/category-3.phtml')->toHtml();
to 至
$this->getLayout()->createBlock('homepage/product_slider3') ->setTemplate('homepage/catalog/product/category-3.phtml')->toHtml();
To display this block content, you can also call like this since you are not using any frontend layout 要显示此块内容,您也可以像这样调用,因为您没有使用任何前端布局
$this->getLayout()->createBlock('homepage/product_slider3');
In addition to the typo in the block name that Jickson has mentioned- You should never create the block programmatically within a template. 除了Jickson提到的块名称中的错字以外,您永远不要在模板中以编程方式创建块。 Instead, use Layout XML to add your block in to the block you need to call it from.
相反,使用布局XML将您的块添加到需要从中调用它的块中。 Then, use
$this->getChildHtml()
within that block's template file to call your new block. 然后,在该块的模板文件中使用
$this->getChildHtml()
来调用您的新块。
Creating it manually is essentially bypassing the framework, which defeats the purpose of using it. 手动创建它实际上是在绕过框架,这违背了使用它的目的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.