What is difference between getSingleton and getModel in magento. It's very important question for interview in Magento. Every Interviewer asked this question.
Mage::getSingleton()
Mage::getSingleton() is first check the object are created or not. If the object is created then return existing object. If the object is not created then it will create. So Mage::getSingleton() faster than Mage::getModel().
1. $getproduct1 = Mage::getSingleton('catalog/product');
2. $getproduct2 = Mage::getSingleton('catalog/product');
$getproduct1 and $getproduct2 both are have same memory and return only one object each time.
Mage::getModel()
Mage::getModel() is always create new object.
1. $getproduct1 = Mage::getModel('catalog/product');
2. $getproduct2 = Mage::getModel('catalog/product');
$getproduct1 and $getproduct2 both have different object and also have different memory .
Mage::getSingleton()
Mage::getSingleton() is first check the object are created or not. If the object is created then return existing object. If the object is not created then it will create. So Mage::getSingleton() faster than Mage::getModel().
1. $getproduct1 = Mage::getSingleton('catalog/product');
2. $getproduct2 = Mage::getSingleton('catalog/product');
$getproduct1 and $getproduct2 both are have same memory and return only one object each time.
Mage::getModel()
Mage::getModel() is always create new object.
1. $getproduct1 = Mage::getModel('catalog/product');
2. $getproduct2 = Mage::getModel('catalog/product');
$getproduct1 and $getproduct2 both have different object and also have different memory .
Very effective difference between getSingleton() and getModel. Thanks for the post, keep updating.
ReplyDeletelycopene capsules
Really, a great difference, thanks for it, and keep updating.
ReplyDeletegallbladder surgery in india
Laparoscopic Appendix Surgery Hospital Delhi
ReplyDeleteAbdominoplasty Treatment In Delhi
Tummy Tuck Treatment In Delhi