开发者

how do i save array in magento session?

I would like to开发者_JS百科 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜