how do i save array in magento session?

后端 未结 1 1441
天命终不由人
天命终不由人 2020-12-30 16:43

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

相关标签:
1条回答
  • 2020-12-30 17:11

    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 讨论(0)
提交回复
热议问题