Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i save array in magento session?

Tags:

magento

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

like image 774
balanv Avatar asked Mar 21 '11 12:03

balanv


1 Answers

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'.

like image 56
Josh Avatar answered Nov 07 '22 14:11

Josh