Hello everyone. I have a question that I hope you can help me with. I've been programming in PHP for some time, but I'm new to using object oriented programming with AJAX. I'm working on a complex application and am in the drawing board stage. I just would like to know a bit about how best to maintain state in an AJAX application.
Basically I am creating an e-commerce application which will require the user to make several choices before finally allowing them to put in their credit card and make a payment. I am encapsulating the user's choices in a class along the way. The class also has several methods which perform calculations based on the choices that the user makes and returns more data.
I'm assuming that with an AJAX call, I can instantiate the class and request some data, but the class does not stay in memory from one AJAX call to the next, correct?
So in that case, what is the best way to maintain the state of the application (and the class) from one AJAX call to the next? Do I use the magic methods __sleep and __wakeup and store the relevant class data in the session? Do I write the relevant choices that the user has already made to a mysql database, and read them back when the user makes the next ajax call? If so there would be a lot of cleanup involved for those users that don't complete the application.
I'm sorry if this is an obvious question, and hope that someone can help me understand how this all works a bit better.
PHP, Ajax, and Classes
Moderator: General Moderators