资源模型和magento模型的区别


difference between resource model and model in magento

这两种语法之间有什么区别?

1) Mage::getModel('catalog/product')->load('1');

2) Mage::getResourceModel('catalog/product')

法师::getModel()

每次配置中存在对象时,Mage::getModel()都会创建一个新的对象实例。

示例

$product1 = Mage::getModel('catalog/product');
$product2 = Mage::getModel('catalog/product');

$product1和$product2都具有相同对象的不同瞬间,并且占用不同的内存

法师::getResourceModel()

据我所知,Magento的所有藏品都是资源模型。它们由实例化

Mage::getResourceModel() 

Mage::getModel()->getCollection()

你使用哪种功能其实并不重要;后一个简单地称为第一个。Magento团队只是选择将集合作为资源的一部分,可能是因为集合需要大量查询数据库。通常,您不必为集合以外的任何其他内容调用Mage::getResourceModel()

请参阅下面的链接http://alanstorm.com/magento_models_orm