30 Oct 2013

Here Are Code To Get, Set, And Unset Session In Magento

Magento allows the functionality to set the the value into session and get it where you want and unset too.There are three different modules magento uses for handling the session variable.Most common is the core module for handling the session variable that is'core/session' .For using the session variable magento uses most favourable methods 'setter' and getter like to set session set(your variable name) and to retrieving the session get.So lets starts for more details how to use variable for set,get and unset session variables.


Set Session :
Set session with variable Name 'mySessionVariable'. The session value here is 'MyValue'.

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


Get Session :
Get session 'mySessionVariable'

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


Unset session :

Mage::getSingleton('core/session')->setMySessionVariable();


or

Mage::getSingleton('core/session')->unsMySessionVariable();


Note: Use customer or core session in frontend. Use adminhtml session in the backend.
Core Session :-
Mage::getSingleton('core/session')


Customer Session :-
Mage::getSingleton('customer/session')


Admin Session :-
Mage::getSingleton('adminhtml/session')


No comments:

Post a Comment