How to save an array in a magento session?

I would like to store an array in a session variable, how to do this with a magento session? and this array must be updatable, i.e. I will add values ​​to this array during various actions performed by the user.

can someone give me a hint of this.

thank

+5
source share
1 answer

The easiest way to do this is to use the setData method of the client session object:

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

You can get it later using getData and then use setData again to update it.

You can also create your own session model with your own identifier:

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

, , getSingleton "mymodule/session", "/".

+22

All Articles