Magento getSingleton confusion

Discussion in 'Website Development & Design' started by Boby Smith, Apr 10, 2013.

  1. Boby Smith

    Boby Smith
    uix_expand uix_collapse

    Dec 15, 2011
    Likes Received:
    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 code that does this:


    I don't know PHP, but I think I can make a safe assumption from the 'getSingleton' method name that there will be only one instance of the class specified (the class being specified as a grouped class name, and resolving to app/code/core/Mage/Customer/Model/Session.php - containing class Mage_Customer_Model_Session.

    Question 1 - how did the getSingleton method know to look in the Model folder for the class?

    Question 2 - so there is one instance of the class for the whole ... I want to say JVM as I am from a Java background, but I'll say PHP engine in the hope that that is vaguely the correct terminology; the Mage_Customer_Model_Session is not passed in a customer id or any such identifier, yet we call the method isLoggedIn()! Give there is not a Mage_Customer_Model_Session instance per customer, how can we ask a singleton if a customer is logged in when we do not tell it what customer we are talking about?

    Question 3 - I've seen calls to Mage::getSingleton('core/session') and to Mage::getSingleton('customer/session') - what is the difference?

Share This Page