如何在 magento 会话中保存数组? [英] how do i save array in magento session?

查看:37
本文介绍了如何在 magento 会话中保存数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 session 变量中保存一个数组,我如何使用 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.

谁能给我一个提示..

谢谢

推荐答案

最简单的方法是使用客户会话对象的 setData 方法:

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 ) );

您可以稍后使用 getData 检索它,然后再次使用 setData 来更新它.

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' );
    }
}

然后您以相同的方式访问它,除了 getSingleton 将使用mymodule/session",而不是customer/session".

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

这篇关于如何在 magento 会话中保存数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆