duanchuli5647 2016-03-22 12:40
浏览 36

如何将会话数组保存到数据库中?

I'm learning MVC with Symfony2 by attempting to build a simple shopping cart. I'm using the FOSUserBundle and have an Admin view and a normal (or user) view. I'm a newbie with Symfony and PHP.

Setup: I have an associative session array (cartArray) which contains the id, the name, and the price of the products selected by a 'normal' user...

array(3) { [5]=> array(3) { [0]=> string(7) "Rooster" [1]=> int(1) [2]=> float(105) } 
           [6]=> array(3) { [0]=> string(11) "Apple Sauce" [1]=> int(1) [2]=> float(9.25) }
           [1]=> array(3) { [0]=> string(5) "Water" [1]=> int(5) [2]=> float(2.75) } 
}

... I want that information to be posted into my database so I can retrieve it for my Admin view (created from FOSUserBundle) so that on that page there would be 2 tables.

  • Table 1: All session arrays being used. (From the start of session array until the user selects to buy those products)
  • Table 2: All products bought (after the user selects buy)

Details: 'Normal' user is brought to a screen after they sign in which shows products. Once they click 'Add Product to Cart', the product gets added to cartArray. Once they click 'Proceed to Checkout', they can select 'Buy' and then the session array is emptied: $request->getSession()->invalidate(1);

In the research I've done like this and or this (those two examples are not all) fail to give answers using Symfony or non associative arrays.

Any help would really be appreciated and if more information is needed, I'll be happy to provide it. Thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?
    • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
    • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
    • ¥15 cmd cl 0x000007b
    • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line