0

I am setting a session variable on an event triggered when the url have an extra variable name "pcode" with the following code.

Mage::getSingleton('core/session')->setPcode($pcode);

Now when getting the session from one of template file with the following code..

$data=Mage::getSingleton('core/session')->getPcode();
Mage::Log($data);

*Edit:*Enable the log From back-end and checked

but I am getting nothing.

I also tried the same code by calling a model and also from calling an ajax function from the template but have the same results.

Edit:

When I am getting the session value after setting get, it retrieves the value but in another template page, its have no value.

$request = $observer->getEvent()->getData('front')->getRequest();
        $pcode  = $request->pcode;
        if(isset($pcode))
            //Mage::getModel(‘core/cookie’)->set('pcode', $pcode);
            Mage::getSingleton('core/session')->setPcode($pcode);
            $data=Mage::getSingleton('core/session')->getPcode();
                Mage::Log($data);
        exit;

Edit: Enable the log From back-end and check in var/log/system.log file your value will logged or not.

3

you can set the session using set, getting value using get and unset session using uns.

Mage::getSingleton(‘core/session’)->setMySessionVariable(‘MyValue’); 

$myValue  =  Mage::getSingleton(‘core/session’)->getMySessionVariable();

echo $myValue;

To Unset the session

Mage::getSingleton(‘core/session’)->unsMySessionVariable();
  • I am using the same method but unable to get the session. what's wrong with my code?? – Tariq Aziz Feb 5 '14 at 7:08
  • check you got value in $pcode or not – Keyul Shah Feb 5 '14 at 7:09
  • When I put the code echo Mage::getSingleton('core/session')->getPcode(); exactly after setting it, I am getting the value. however later in a template file, noting is retrieved. – Tariq Aziz Feb 5 '14 at 7:12
  • means your session is expired some how – Keyul Shah Feb 5 '14 at 7:13
  • No its not expired, I have modified the question, plz review. – Tariq Aziz Feb 5 '14 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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