如何覆盖 Magento 中的本地模块?
有很多关于如何覆盖 Magento 中核心模块的示例,但是如何覆盖本地模块呢?
There are many examples of how to override a core module in Magento, but how does one override a local module?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不重写模块,而是重写(或者更准确地说,
重写
,见下文)属于模块或属于常规lib
文件夹的类。根据您的措辞,我认为覆盖您的意思是“从
app/code/core/
获取一个类”并将其放在“app/代码/本地/
”?如果是这样的话,那么你基本上不能。代码池之所以有效,是因为 magento 在 PHP 包含路径中添加了四个路径。然后,当自动加载器表示
是否将首先检查
local
文件夹,然后是community
文件夹,然后是 core 文件夹,最后是lib
文件夹。local
文件夹始终获胜。如果您的类是模型、助手或块,我建议使用基于模块的重写系统。用于重写核心模块中的类的相同技术也可用于重写本地或社区模块中的类。基于模块的系统的要点在于,运行核心系统的代码的插入/行为方式与其他人可能添加到系统中的代码相同。
You don't override a module, you override (or, more properly,
rewrite
, see below) a class that belongs to a module, or belongs to the generallib
folder.Based on your wording, I assume by override you mean "taking a class from
app/code/core/
" and placing it in "app/code/local/
"? If that's the case then you mostly can't. Code pools work because magento adds four paths to the PHP include path.Then, when the autoloader says
if will first check the
local
folder, then thecommunity
folder, then the core folder, and finally thelib
folder. Thelocal
folder always wins.If your class is a Model, Helper, or Block, I'd suggest using the module based rewrite system. The same techniques you use to rewrite classes in the Core modules can be used to rewrite classes in local or community modules. The point of a module based system is that the code which runs the core system is inserted / behaves the same way as code other people might add to the system.