1

If I can use session to store a variable like this

$session = Mage::getSingleton('core/session')->setData('Message');

then what is the use of

$session = Mage::getSingleton('core/session', array('name'=>'frontend')); what does this code actually do.

2 Answers 2

2

In a default out of the box Magento installation you have two options for the session.

  1. adminhtml - set in Mage_Adminhtml_Controller_Action
  2. frontend - set in Mage_Core_Controller_Front_Action

When the Mage_Core_Controller_Varien_Action runs it's preDispatch function it will start the session for the appropriate section.

$session = Mage::getSingleton('core/session', array('name' => $this->_sessionNamespace))->start();

The construct of the session will take in the name of the section you are in, frontend or adminhtml, and will limit the data that you can access.

public function __construct($data=array())
{
    $name = isset($data['name']) ? $data['name'] : null;
    $this->init('core', $name);
}
1

its means you session variable has only access to frontend session.you cant access admin session with the above code.

1
  • so this code is used only for the frontend, Thanks Pradeep.
    – Waseem
    Commented Jan 23, 2014 at 6:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.