Magento XML 覆盖面向未来
我知道 Magento 最佳实践模式说,如果我想修改 Magento 的核心文件之一,我应该将该文件(和匹配的目录树结构)从 /app/code/core 复制到 /app/code/本地并修改副本以使其覆盖原始副本。我需要使用 Magento 的核心 XML 文件之一来执行此操作 - 我已经修改了该文件,并且我想确保以后升级 Magento 时它不会被覆盖。
现在,我有一个修改版本 /app/code/core/Mage/Page/etc/config.xml - 我对其进行了编辑以添加我的网站所需的特定页面布局。现在我想将我的修改移出核心文件。我是否在 /app/code/local/Mage/Page/etc/config.xml 中重新创建整个 XML 文件,或者我只需要将添加和更改放入本地覆盖文件中?
如果是后者,有人可以向我解释一下它的结构吗?
I'm aware of the Magento best-practices pattern that says that if I want to modify one of Magento's core files, I should copy the file (and matching directory tree structure) from /app/code/core into /app/code/local and modify the copy so that it overrides the original. I need to do that with one of Magento's core XML files - I've modified the file, and I want to make sure that it doesn't get overwritten later when I upgrade Magento.
Right now, I have a modified version /app/code/core/Mage/Page/etc/config.xml in place - I edited it to add in a specific page layout that I need for my site. Now I want to move my modification out of the core files. Do I recreate the entire XML file in /app/code/local/Mage/Page/etc/config.xml, or do I only need to put my additions and changes into a local override file?
If it's the latter, can someone explain the structure of this to me please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能以这种方式完全“覆盖”config.xml 文件。
Magento 由代码模块组成。
Mage_Page
是一个单独的模块。模块包含一个 config.xml 文件和许多 PHP 文件。您可以通过在 Magento 中放置替换来覆盖 Magento 中某些类型的 PHP 文件
这是因为 __autoloader 创建如下所示的 include 语句
,并且 PHP 将检查每个代码池中的文件。
通过在本地放置替换文件,Magento 首先找到您的文件并跳过核心文件。
您不能使用
config.xml
执行同样的操作。如果您将 config.xml 文件放置在Magento 中,则会忽略它。当您在 Magento 中请求页面时,系统将创建活动模块列表(来自
app/modules/etc
),然后加载每个模块的 config.xml 文件。您根本不应该更改核心 config.xml 文件。根据您的问题,听起来您更改了此
config.xml
文件以添加额外的layout.xml
文件。如果是这种情况,那么您要做的就是此页面(自链接)涵盖了安装新模块所需的基本文件。但是,不要将观察者内容添加到
config.xml
中,而是添加新的布局节点You can't exactly "override" a config.xml file that way.
Magento is made up of code modules.
Mage_Page
is a single module. A module contains aconfig.xml
file, and numerous PHP files.You can override certain types of PHP files in Magento by placing a replacement in
That's because the __autoloader creates include statements that look like this
and PHP will check each code pool for a file.
By placing a replacement file in local, Magento finds your file first and skips the core file.
You can't do the same thing with
config.xml
. If you place a config.xml file atMagento will ignore it. When you request a page in Magento, the system will create a list of active modules (from
app/modules/etc
), and then load each module's config.xml file. You shouldn't be changing core config.xml files at all.Based on your question, it sounds like you changed this
config.xml
file to add an additionallayout.xml
file. If that's the case, then what you want to do isconfig.xml
file, add the new layout node.This page (self link) covers the basic files you need to get a new Module in place. However, instead of adding the observer stuff to
config.xml
, add your new layout node instead如果不是太多 xml,您可以将其弹出到 app/etc/local.xml 中,这就是我倾向于对自定义布局执行的操作。
例如
If it's not too much xml, you can pop it into app/etc/local.xml which is what I tend to do for custom layouts.
E.g.