multidimensional array session container in zend framework 2

杀马特。学长 韩版系。学妹 提交于 2019-12-10 11:19:01

问题


I am working on an application using zend framework 2 session array containers. I can create the session using array containers as mentioned in zend 2 document, but i am getting the problem while creating the session with multidimensional arrays. I want to update the session everytime since i am updating the values for shopping cart. I am trying with the below code, its not updated rather the session values are getting changed.

$container = new Container('test');
$values = array();
$values['one'] = '1';
$values['two'] = '2';
$container->item = $values; // Now the session contains the $values array 1,2


$container = new Container('test');
$values['one'] = '3';
$values['two'] = '4';
$container->item = $values; // Here the session values are 3,4 and 1,2 is not updating

I tried also with OffsetGet and OffsetSet methods as below, but the session values are not updated.

$container = new Container('test');
$session = $container->offsetGet('item');
$values['one'] = '3';
$values['two'] = '4';
$session = $container->offsetSet('item', $values); // results are 3,4

I am expecting the results as below,

Array
(
    [0] => Array
        (
            [values] => Array
                (
                    [one] => 1
                    [two] => 2
                )

        )

    [1] => Array
        (
            [values] => Array
                (
                    [one] => 3
                    [two] => 4
                )

        )

)

How i can obtain the multidimensional session arrays in zend 2 ? Thanks.

来源:https://stackoverflow.com/questions/18713047/multidimensional-array-session-container-in-zend-framework-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!