多页结帐 - 传输数据
我正在一家小型电子商店中进行简单的结帐,我想为用户提供最终评论的选项。所以流程是篮子 -> 买家信息 -> 订单审核 -> 订单确认。
现在的问题是,在第 2 阶段和第 3 阶段之间传输数据的最佳方式是什么?
一种选择是使用 HTML 和隐藏表单字段。缺点是我必须在第 3 阶段之后进行另一次输入检查(因为输入可以由用户修改)。
另一种选择是使用会话。由于订单存储在对象(Sf2 实体)中,我必须将其转换为数组,然后再将其转换回来。另外,我读到,将太多数据放入会话变量会对性能产生负面影响。
第三个选项是存储在数据库中,但我不希望在最终确认之前存储任何内容。
还有更好的选择吗?
I'm doing a simple checkout in a small eshop and I'd like to give the user the option of a final review. So the flow is Basket -> Buyer information -> Order review -> Order confirmation.
Now the question is, what would be the best way to transfer the data between phase 2 and 3?
One option is to use HTML and hidden form fields. The downside is that I have to do another input check after phase 3 (since the input is modifiable by user).
Another option is to use sessions. As the order is stored in an object (Sf2 Entity), I'd have to convert it to an array and later convert it back. Also, I've read that putting too much data into session variables can have negative effect on the performance.
Third option would be storing in the db but I'd prefer not to store anything until final confirmation.
Are there any better options?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为会话变量在这里应该没问题,除非你有大量的表单数据。如果您担心内存问题,您可以在最终确认后随时删除该数据。
I think session variable should be fine here, unless you have a ton of form data. You can always remove that data after final confirmation if you worried about memory.
您可以将这些数据存储在缓存级别(如 APC 或 Memcached)并设置过期时间。
或者,就像 Yii 的解决方案一样,使用隐藏输入,并将值设置为: hash(secret + base64(data )) + base64(data),你应该在第 3 阶段首先验证哈希值
。忘了我糟糕的英语了。 :)
You can store these data in cache level (like APC or Memcached) and set a expires time.
Or, Just like Yii's solution, Use a hidden input, and set the value as: hash(secret + base64(data)) + base64(data), and you should validate the hash first in phase 3.
Forgot my bad English. :)
会话非常适合这项工作。您可以调整会话处理,以便将数据存储在数据库中。就这一点而言,缓存并不更快,因为它也只是一个数据库读/写过程。
Sessions are just fine for that job. You can adjust the session handling so that the data is stored in a database. cacheing isn't faster for that matters as it is also just a database-read/-write procedure.
我会用 flashdata 将它保存在会话中。这非常有效,并且会话会在您需要时被清除。
在 symfony 2 中使用 flashdata:
I would save it in the session, with flashdata. This works perfect and the session is cleared when you want.
To use flashdata in symfony 2: