如果重写我的模块中被另一个模块使用的类会发生什么?


what will happen if overriding a class in my module used by another module

我正在一个模块上工作,我需要一个块文件被覆盖,以便添加新的功能。我知道如何重写模型控制器,但我想知道,如果我扩展的类被另一个模块类使用会发生什么?

上述场景如下:
在我的模块config.xml中,我将块文件重写为:

<blocks>
    <checkout>
        <rewrite>
            <cart_shipping>Company_Module_Block_Cart_Shipping</cart_shipping>
        </rewrite>
    </checkout>
</blocks>

和重写方法getEstimateRates()

,但有另一个模块,其块文件扩展Mage_Checkout_Block_Cart_Shipping。我的问题是-

"那个类能看到我的模块中被覆盖的类所做的更改吗?"

"我必须重写其他模块块文件吗?"

您的一个或另一个扩展块将无法工作。它可以通过从其中一个扩展您的块或另一个块来修复。

例如,Company_Module_Block_Cart_Shipping是您的块,Other_Module_Block_Cart_Shipping是其他块。

如果Other_Module_Block_Cart_Shipping从core扩展,则必须从Other_Module_Block_Cart_Shipping扩展Company_Module_Block_Cart_Shipping

Magento生成一个config.xml树,其中包含所有已启用模块的config.xml。

首先加载

Mage_All.xml,那么所有法师。* . xml在它之前是按字母顺序排列的自定义模块。xml。

如果您在etc/modules/module definition xml中给出了一个depends标签,则可以更改顺序。

希望这能消除你的疑虑。