To set a Magento session variable:
$myValue = 'Hello World';
Mage::getSingleton('core/session')->setMyValue($myValue);
To Retrieve:
$myValue = '';
$myValue=Mage::getSingleton('core/session')->getMyValue();
To Unset:
Mage::getSingleton('core/session')->unsMyValue();
Note that ‘MyValue’ can be any text you want but ‘set’, ‘get’ and ‘uns’ prefixes are required.
10 responses to “Magento Set, Retrieve and Unset Session Variables”
I enjoyed this! Well done!
Got it! Thanks a lot again for hleipng me out!
This wasn’t actually that helpful. At this point in the game I have a good handle on magic methods. But how do I mess with a session that’s not the one I’m currently in? I’m working with a swf and that doesn’t count as the same session apparently.
Great..dude…thanks..
That just saved my day! Thanks a bunch.
Great ya…
very useful, thenks.
kykltuil
Nice information.. Than x for providing this..!
Mage::getSingleton(‘core/session’)->setMyValue(123);
calling the line above in a class extending Mage_Core_Block_Messages.
Result:
__clone method called on non-object in
Why?!