Magento: 两个模块能否扩展同一个核心模型?

4

是否可以创建两个扩展相同核心模型的模块,例如 Mage_Customer_Model_Customer

访问(重载)核心模型时会收到什么?


相关问题:https://dev59.com/mmUq5IYBdhLWcg3wEcXu - Mukesh Chapagain
1个回答

4

您可以将Model类扩展到自定义的模型中:

class Namespace_Module_Model_Customer1 extends Mage_Customer_Model_Customer

该内容定义在app/code/local/Namespace/Customer/Model/Customer1.php中:

class Namespace_Module_Model_Customer2 extends Mage_Customer_Model_Customer

这个代码文件定义在app/code/local/Namespace/Customer/Model/Customer2.php中。

没问题 - 当你调用它时,你需要指定想要使用的模型:

Mage::getModel('namespace/customer1')->method()

或者
Mage::getModel('namespace/customer2')->method()

核心模型将保持不变:
Mage::getModel('customer/customer')

3
关于语言的一点说明:你不是在扩展模块,而是在扩展模型模块允许你将自己的代码添加到系统中。模型是从类实例化的常规PHP对象。一个模块可以有多个模型。 - Alana Storm

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接