如何正确覆盖 Magento 中的模型? [英] How override model in Magento correctly?
本文介绍了如何正确覆盖 Magento 中的模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
伙计们.
我需要覆盖不同类中的 2 个函数(CatalogSearch/Layer.php 和 CatalogSearch/Mysql4/Fulltext/Collection.php).所以,我有一个配置文件:
I need to override 2 functions in different classes (CatalogSearch/Layer.php and CatalogSearch/Mysql4/Fulltext/Collection.php). So, I have a config file:
<config>
<modules>
<my_modulename>
<version>0.1</version>
</my_modulename>
</modules>
<global>
<models>
<catalogsearch>
<rewrite>
<layer>My_Modulename_Model_CatalogSearch_Layer</layer>
<mysql4_fulltext_collection>My_Modulename_Model_CatalogSearch_Mysql4_Fulltext_Collection </mysql4_fulltext_collection>
</rewrite>
</catalogsearch>
</models>
</global>
</config>
因此,Layer.php 已被正确覆盖,但 Collection.php 没有 - '/local/My/Modulename/Model/CatalogSearch/Mysql4/Fulltext/Collection.php' 甚至不包括在内.为什么?
Hence, Layer.php has been overridden correctly , but Collection.php hasn't - '/local/My/Modulename/Model/CatalogSearch/Mysql4/Fulltext/Collection.php' was not even included. Why?
感谢您的帮助.
推荐答案
资源模型可能是分开处理的,试试这个:
The resource models are probably handled separately, try this:
<global>
<models>
<catalogsearch>
<rewrite>
<layer>My_Modulename_Model_CatalogSearch_Layer</layer>
</rewrite>
</catalogsearch>
<catalogsearch_mysql4>
<rewrite>
<fulltext_collection>My_Modulename_Model_CatalogSearch_Mysql4_Fulltext_Collection</fulltext_collection>
</rewrite>
</catalogsearch_mysql4>
</models>
</global>
这篇关于如何正确覆盖 Magento 中的模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文