[英]Magento - Extending Topmenu.php block stops the topmenu.phtml template loading
I'm extending app/code/core/Mage/Page/Block/Html/Topmenu.php with the following xml: 我正在使用以下xml扩展app / code / core / Mage / Page / Block / Html / Topmenu.php:
<config>
<modules>
<Custom_Menu>
<version>1.0</version>
</Custom_Menu>
</modules>
<global>
<blocks>
<page>
<rewrite>
<html_topmenu>Custom_Menu_Block_Page_Html_Topmenu</html_topmenu>
</rewrite>
</page>
</blocks>
</global>
</config>
And my class definition: 而我的班级定义:
class Custom_Menu_Block_Page_Html_Topmenu extends Mage_Page_Block_Html_Topmenu
{
}
Even with my class not overriding any methods, the following template file just doesn't get processed: 即使我的类没有覆盖任何方法,以下模板文件也不会被处理:
app/design/frontend/base/default/template/page/html/topmenu.phtml
I'm not overriding the template file. 我没有覆盖模板文件。
As soon as I disable my module, it starts working again. 一旦我禁用我的模块,它就会重新开始工作。
Do I need to declare anything else in my xml file? 我是否需要在xml文件中声明其他内容?
Do this change in your config.xml file 在config.xml文件中进行此更改
<html_topmenu>Custom_Menu_Block_Html_Topmenu</html_topmenu>
and change your class name to 并将您的班级名称更改为
class Custom_Menu_Block_Html_Topmenu extends Mage_Page_Block_Html_Topmenu
{
}
One thing springs to mind. 有一件事让人想起。 You may have your class file in the wrong place.
您可能将您的类文件放在错误的位置。 Your rewrite code looks correct, so when Magento instantiates a
page/html_topmenu
block it correctly resolves it to your Custom_Menu_Block_Page_Html_Topmenu
class name. 您的重写代码看起来是正确的,因此当Magento实例化一个
page/html_topmenu
块时,它会正确地将其解析为您的Custom_Menu_Block_Page_Html_Topmenu
类名。 However, Magento may not be able to find the class Custom_Menu_Block_Page_Html_Topmenu
. 但是,Magento可能无法找到
Custom_Menu_Block_Page_Html_Topmenu
类。 Try running the code 尝试运行代码
$block = new Custom_Menu_Block_Page_Html_Topmenu;
var_dump($block);
from an empty controller and/or bootstrap file to ensure that Magento can find your class. 从空控制器和/或引导程序文件,以确保Magento可以找到您的类。 It also wouldn't hurt to run
跑步也不会有害
$block = Mage::getSingleton('core/layout')->createBlock('page/html_topmenu');
var_dump($block);
To ensure your rewrite is doing what it needs to do. 确保您的重写正在执行它需要做的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.