Store data between
Added by ronald viscarra over 10 years ago
Hi, I already readed "Best way to send data from a session to another ?" but I don't get how to do a global vector to keep info of the session, any time I print a session id from application its all time a new value. If I change the reload-is-new-session to false, the session id it's visible at the url, behaviour not expected.
For instance, I want something like a shopping cart behaviour.
Thanks
Replies (4)
RE: Store data between - Added by Zalu Hobgobicus over 10 years ago
I'm not certain I follow, but it sounds like you just want to keep some data in a session, like what a user has ordered for a shopping cart?
If so, I would think to just add your vector as a data member of your session WApplication class.
class ShoppingWebApp : public WApplication
{
// Constructor/Destructor:
public:
ShoppingWebApp(const WEnvironment& env);
~ShoppingWebApp();
// Authentication:
public:
void authEvent();
// Shopping cart:
std::vector ShoppingCart;
...
RE: Store data between - Added by Zalu Hobgobicus over 10 years ago
Zalu Hobgobicus didn't format well:
class ShoppingWebApp : public WApplication
{
// Constructor/Destructor:
public:
ShoppingWebApp(const WEnvironment& env);
~ShoppingWebApp();// Authentication:
public:
void authEvent();// Shopping cart:
std::vector ShoppingCart;...
RE: Store data between - Added by Koen Deforche over 10 years ago
Hey,
You need to save the user identity across sessions using cookies. See:
http://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WApplication.html#a5d10106d4131611aa98e20e6a82b3c40
http://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WEnvironment.html#af39745ca2c6c6fc00c0f78bc7d064e3a
The data itself (shopping cart contents) is probably best saved in a database, but a light weight single process solution could also store it in a some global data-structure in memory.
Koen
RE: Store data between - Added by ronald viscarra over 10 years ago
Hi, thanks, I just did that way and is working as expected.