how do i save array in magento session?

I would like to save an array in session variable, how do i do it with magento session?
and this array should be updatable, ie., i will add values to this array at different actions performed by user.

could someone give me a hint on this..

Thanks

One thought on “how do i save array in magento session?”

  1. The easiest way of doing this is to use the setData method of the customer session object:

    Mage::getSingleton( 'customer/session' )->setData( 'yourArray', array( 1, 2, 3 ) );
    

    You can retrieve it later with getData and then use setData again to update it.

    You can also create your own session model, with it’s own identifier:

    class Example_MyModule_Model_Session extends Mage_Core_Model_Session_Abstract
    {
        public function __construct()
        {
            $this->init( 'mymodule' );
        }
    }
    

    Then you access it the same way, except getSingleton would use ‘mymodule/session’, rather than ‘customer/session’.

Leave a Reply

Your email address will not be published. Required fields are marked *