本文介绍了Magento:如何在本地模块中覆盖模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图覆盖本地文件夹中的一个模块,该模块也位于本地文件夹中,但是我不知道是否可能.这就是我所做的.

I'm trying to override in the local folder a module which is in the local folder also, but I don't know if it's possible. This is what I've done.

我已经创建了/local/Mycompany/Modulename/Model/Model.php,我想覆盖/local/Othercompany/Modulename/Model/Model.php

I've created /local/Mycompany/Modulename/Model/Model.php which i'd like to override the /local/Othercompany/Modulename/Model/Model.php

我的model.php是:

my model.php is:

class Mycompany_Modulename_Model_Model extends Othercompany_Modulename_Model_Model 

{...}

和我的config.xml

and my config.xml

<global>
<models>
    <othercompanymodulename>
    <rewrite>
        <model>Mycompany_Modulename_Model_Model</model>
    </rewrite>
    </othercompanymodulename>
</models>

该类已通过Mage :: getModel('othercompanymodulename/model')实例化

The class is been instantiated whith Mage::getModel('othercompanymodulename/model')

我的Mycompany_Mymodule.xml

My Mycompany_Mymodule.xml

<config>
<modules>
    <Mycompany_Modulename>
        <active>true</active>
        <codePool>local</codePool>
    <depend>
        <Othercompany_Modulename/>
        </depend>
    </Mycompany_Modulename>
</modules>

但是我的模块被忽略了.是否可以覆盖本地文件夹中的某个类,该类也位于本地文件夹中?我在做什么错了?

But my module is ignored. Is possible to override in local folder a class located also in local folder? What I'm doing wrong?

推荐答案

打开您的 [magento] \ app \ etc \ modules \ Mycompany_Modulename.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_Modulename>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Othercompany_Modulename/>
            </depends>
        </Mycompany_Modulename>
    </modules>
</config> 

以上代码强制Othercompany_Modulename首先加载.

above code force Othercompany_Modulename to load first.

希望对您有帮助

这篇关于Magento:如何在本地模块中覆盖模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 04:58