[英]Magento quick getResourceModel question
What class (if any) is called with this line of code? 用这行代码调用什么类(如果有的话)?
Mage::getResourceModel('sales/order_invoice_collection')
Essentially I"m trying to figure out what database table is accessed with this resource model and how I can tweak that. Thanks! 本质上,我试图找出使用此资源模型访问的数据库表以及如何调整它。谢谢!
The class you are looking for is this: 你要找的课是这样的:
Mage_Sales_Model_Mysql4_Order_Invoice_Collection
located in app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Collection.php
. 位于
app/code/core/Mage/Sales/Model/Mysql4/Order/Invoice/Collection.php
。
If you take a look at the configuration for the sales module app/code/core/Mage/Sales/etc/config.xml
, you can see the table name in the definition of the resource models: 如果您查看销售模块
app/code/core/Mage/Sales/etc/config.xml
,您可以在资源模型的定义中看到表名:
<config>
<global>
<models>
<sales_mysql4>
<entities>
...
<invoice><table>sales_flat_invoice</table></invoice>
...
</entities>
</sales_mysql4>
</models>
</global>
</config>
To learn more about how Magento interacts with the database, you should read about models, resource models, and collections: 要了解有关Magento如何与数据库交互的更多信息,您应该阅读有关模型,资源模型和集合的信息:
http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-5-magento-models-and-orm-basics http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-5-magento-models-and-orm-basics
Try this to get the class resulting from a statement: 试试这个来获得一个声明产生的类:
$obj = Mage::getResourceModel('sales/order_invoice_collection');
print get_class($obj);
In this instance it is loading 在这种情况下,它正在加载
code/Core/Mage/Sales/Model/Mysql4/Order/Invoice/Collection.php
which is class name: 这是班级名称:
Mage_Sales_Model_Mysql4_Order_Invoice_Collection
This can be determined by looking at the config.xml: 这可以通过查看config.xml来确定:
code/Core/Mage/Sales/etc/config.xml.
In it under the models tag is the sales tag, which you know from 'sales' before the slash in the string. 在模型标签下面是sales标签,您可以在字符串中的斜线之前从'sales'中获知。 There it defines the resource model as sales_mysql4.
在那里它将资源模型定义为sales_mysql4。 So, if you call:
所以,如果你打电话:
Mage::getResourceModel('module/everything_else')
the file loaded will be: 加载的文件将是:
Module/Model/{contents of resourceModel tag}/Everything/Else.php
Hope that helps. 希望有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.