Reputation: 3658
I have some questions related to symfony 2 form component,
Lets say I have an entity which has a field "created_by" which refers to the user who created that entity. When a new record is created I want to set that field with the logged in user in my app. I can do this is controller ($entity->setCreatedBy($user), but I would prefer to include this login inside the form class itself. I can pass the user object, to the form in constructor/setter method but then how would I "bind" it to the entity? Do I need to create a field in the form? I could make an hidden field but I prefer not showing the user id that way.
Is there any equivalent to updateObject or doSave methods from symfony 1.4?
Thanks for your help
Upvotes: 0
Views: 647
Reputation: 734
You could use a listener and the prePersist event as show here http://symfony.com/doc/2.0/cookbook/doctrine/event_listeners_subscribers.html
Upvotes: 1