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

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

问题描述

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

谢谢

推荐答案

最简单的方法是使用客户会话对象的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天全站免登陆