Magento覆盖核心块 [英] Magento Override Core Block
问题描述
我正在尝试覆盖位于app/code/core/Mage/Catalog/Block/Navigation.php上的Mage_Catalog_Block_Navigation类
I'm trying to override class Mage_Catalog_Block_Navigation located at app/code/core/Mage/Catalog/Block/Navigation.php
我已经创建了这三个文件:
I've created this three files:
1.- app/code/local/Global/Catalog/Block/Navigation.php
1.- app/code/local/Global/Catalog/Block/Navigation.php
2.- app/code/local/Global/Catalog/etc/config.xml
2.- app/code/local/Global/Catalog/etc/config.xml
3.- app/etc/modules/Global_All.xml
3.- app/etc/modules/Global_All.xml
代码:
Global_All.xml
Global_All.xml
<?xml version="1.0"?>
<config>
<modules>
<Global_Catalog>
<active>true</active>
<codePool>local</codePool>
</Global_Catalog>
</modules>
</config>
Config.xml
Config.xml
<?xml version="1.0"?>
<config>
<modules>
<Global_Catalog>
<version>1.0</version>
</Global_Catalog>
</modules>
<global>
<blocks>
<catalog>
<rewrite>
<navigation>Global_Catalog_Block_Navigation</navigation>
</rewrite>
</catalog>
</blocks>
</global>
</config>
Navigation.php
Navigation.php
class Global_Catalog_Block_Navigation extends Mage_Catalog_Block_Navigation
{
protected function _renderCategoryMenuItemHtml(...){
.......rewriting code for this method.......
}
}
我一直在尝试覆盖此方法,但是我不能,有人可以指导我吗?也许检查一些我还没有注意到的错字,或者我错过了什么?
I've been trying to overwrite this method but I can't, can anybody guide me? maybe check for some typo I haven't noticed yet or Am I missing something?
谢谢
推荐答案
好.所以问题是我试图覆盖Magento的核心文件.当我第一次提出问题时,我正在创建一个模块,而不是覆盖现有模块.因此,如果您想以正确的方式覆盖Magento文件,对于您的同事来说,这就是您的做法.很简单.
Ok. So the problem was I was trying to overwrite a core file from Magento. When I first asked the question I was CREATING a module, instead of overwriting an existing one. So for you fellows out there if you want to overwride a Magento file the right way, this is how you do it. Very simple.
我正试图覆盖位于
app/code/core/Mage/Catalog/Block/Navigation.php
app/code/core/Mage/Catalog/Block/Navigation.php
我要做的就是创建相同的根目录和文件夹,尽管它们位于LOCAL文件夹中.话虽如此,这将是我覆盖课程的途径.
All I need it to do, was to create the same root and folders although within the LOCAL folders. Being that said, this would be the route for my overwriting class.
app/code/local/Mage/Catalog/Block/Navigation.php
app/code/local/Mage/Catalog/Block/Navigation.php
请注意本地"而不是核心".尽管我试图覆盖该功能,但Navigation.php基本上是相同的核心文件(复制和粘贴)
Note the LOCAL instead of CORE. The Navigation.php is basically the same core file (Copy & Paste), although the function I was trying to overwrite
function protected function _renderCategoryMenuItemHtml(...)
在newley创建的文件中,将返回另一条与核心文件不同的语句.
within my newley created file, was going to return another statement, different from the core file.
祝你好运.
这篇关于Magento覆盖核心块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!