KevinM1 Posted December 9, 2006 Share Posted December 9, 2006 I'm not sure if this should be here or in the 'application design' section, so please move it to the right spot.I'm currently trying to save my shopping cart object so that when a customer moves from one page to another, their cart's information remains available. Normally, I'd just save their cart in a database, save it when a page exits, and retrieve it when another page loads, but we're not using a database to store any client info (definitely not my design choice). So, I basically have to pass the shopping cart from page to page (using sessions) without any database interaction whatsoever. I'm not 100% sure how to do it, though. I'm thinking of something along the lines of:[code]<?phpinclude('../php_config/config.php'); //this autoloads my classessession_start();if(!isset($_SESSION['cartInfo'])){ $myCart = new ShoppingCart();}else{ $myCart = urldecode(unserialize($_SESSION['cartInfo']));}...?>[/code]My biggest concern is how to save the shopping cart before the user goes to a different page. I'm not sure when to serialize and encode the object in my scripts. I'm also wondering if I should make my shopping cart object a singleton, as logically there is only one cart available to the user.Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/30051-persistant-objects/ Share on other sites More sharing options...
hitman6003 Posted December 9, 2006 Share Posted December 9, 2006 Make the serialization of the cart the last thing you do before outputting data to the user. Then any other functions applied to the cart are always included, rather than using an outdated cart, or being applied to a cart that has already been serialized and saved in the session. Quote Link to comment https://forums.phpfreaks.com/topic/30051-persistant-objects/#findComment-138174 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.