I am writing a small e-shop application with Symfony 2 and I need some way to store the user's shopping cart in a session. I think using a database is not a good idea.
The application will use entities like Product, Category, ShoppingCart where Product and Category are persisted into the database and users will be choosing products into their ShoppingCart.
I have found NativeSessionStorage class which is supposed to save an entity into a session. But there is no written process of implementation into an application.
Do I use this in the controller or in a separated class ShoppingCart? Could you give me a short example of
Don't know if this way is the better way to store your data temporary. You can use this to instantiate a session object :
$session = $this->get("session");
Don't forget the 'use' in your controller :
Then, the session starts automatically when you want to set a variable like :
This is based on the use of the Session class, easy to understand. Commonly definitions :
get(string $name, mixed $default = null) Returns an attribute. set(string $name, mixed $value) Sets an attribute.
Also, take a look to the other ways to store your data : Multiple SessionStorage