Reputation: 391
How can I save datas in my DB from a view in Symfony2.
If I have a entity user and I use:
$user->setInformation("Test");
That information doesn't stored in the DB.
Thanks in advance
Upvotes: 0
Views: 57
Reputation: 673
View shouldn't contain entity persistence/save logic. You should use view only to represent data you get from controller.
$this->getDoctrine is alias to get default entity manager from DI container
So
Upvotes: 1
Reputation: 4283
You should persist and do flush to save the changes in the database. Assuming you are using Doctrine ORM, the below code must work.
$user->setInformation("Test");
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
Upvotes: 1