Multi-page checkout - transferring the data
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 fie开发者_如何学Golds. 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?
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.
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.
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:
$this->get('session')->setFlash('key', 'value');
精彩评论