Magento: Mage::getResourceModel, Mage::getModel 和 Mage::getSingleton() 的区别 when

Perfect differece with example for getsingleton and getmodel.

 

Mage::getSingleton()

Mage::getSingleton() will first check if the same class instance exists or not in the memory. If the instance exists then it will return the same object from the memory. So Mage::getSingleton() is faster than Mage::getModel().

Example

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

 

$product1 and $product2 both will share same memory of OS and return only one instance each time.

 

Mage::getModel()

Mage::getModel() will create a new instance of an object each time even such object exists in configuration.

Example

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

 

$product1 and $product2 both have different instant of same object and also occupy different memory

 

Mage::getResourceModel()

As far as I know, all collections in Magento are resource models. They are instantiated by

Mage::getResourceModel()

 

or

Mage::getModel()->getCollection()

 

(说白了就是:Mage::getResourceModel('module/model_collection') 相当于 Mage::getModel('module/model')->getCollection())

It doesn't really matter which function you use; the latter one simply calls the first one. The Magento team simply chose to make collections part of the resource, probably because collections need to query the database a lot. Usually, you will not have to call Mage::getResourceModel() for anything else than collections.

 

参考:http://stackoverflow.com/a/21154019/602382

实例:Magento: 获取客户信息 Get Customer’s Full Name, First Name, Last Name and Email Address

 

转自:Magento: Mage::getResourceModel, Mage::getModel 和 Mage::getSingleton() 的区别 when to use Mage::getResourceModel, Mage::getModel and Mage::getSingleton()

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
搭建网站是现代社会中非常重要的技能,对于想要在网上展示自己的个人或商业项目而言,手把手搭建网站是一种非常有效的方法。在csdn.net上,你可以找到许多相关资源和教程,以下是一些基本步骤和注意事项: 首先,你需要了解网站的目的和类型。这将有助于你选择合适的平台和工具。例如,如果你想要一个博客类型的网站,你可以选择WordPress、Typecho等。如果你想要一个电子商务网站,你可以选择Magento、WooCommerce等。 其次,你需要选择一个网站主机服务。在csdn.net上,你可以找到许多常见的主机服务提供商的评测和推荐。选择合适的主机服务可以确保你的网站稳定运行和良好的性能。 接下来,你需要选择一个合适的域名并注册。域名代表着你的网站的网址。确保选择一个简洁、易记和与你的网站主题相关的域名。 之后,你可以开始设计和开发你的网站。在csdn.net上,你可以找到许多网页设计和前端开发的教程和资源。你可以学习HTML、CSS和JavaScript等技术,并使用相关的开发工具来编写网页代码。 完成网站的设计和开发后,你可以将网页文件上传到你的主机服务提供的服务器上。这样,你的网站就可以通过域名访问了。 最后,你可以继续优化和改进你的网站。使用合适的SEO技巧可以增加网站的曝光度和访问量。此外,你还可以添加其他功能和插件,如社交分享按钮、在线聊天等,以提升用户体验。 总之,在csdn.net上有许多关于如何手把手搭建网站的资源,从选择平台到设计开发再到优化改进,你都可以找到相关的教程和指南。通过参考这些资源并自己动手实践,你可以掌握搭建网站的技能,并成功创建出一个令人满意的网站。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值