Magento getSingleton confusion

后端 未结 2 569
天命终不由人
天命终不由人 2021-01-29 23:00

I\'m a little confused about calls I see to Mage::getSingleton, and I\'m hoping someone can help me understand a little better.

I have seen a piece of core

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-29 23:42

    1. Magento's getSingleton is almost the same as getModel. The difference is getModel always returns a new instance of a class, and getSingleton creates a new instance of a class only once and then always returns this instance. See the Mage::getSingleton and Mage::getModel methods. Magento knows about looking to the Model folder because of configs in the config.xml file (f.e. Mage/Customer/etc/config.xml). See the Magento wiki for developers to know more about config files.

    2. You do not specify customer directly. It's done automatically by Magento in parent classes of Mage_Customer_Model_Session (see Mage_Core_Model_Session_Abstract_Varien::start() method)

    3. Magento has not one session class to discriminate session data. For example, customer ID is stored in Mage_Customer_Model_Session and error flash message 'Product is not available' will be stored in the Mage_Catalog_Model_Session class.

提交回复
热议问题