views:

355

answers:

1

Hi all, I have a symfony form which have created_at and updated_at field for date. But I want to populate this field with default value and not shown when the form shows. So that, the created_at will hold the current time when inserting new data and updated_at will hold current date when updating any data. Did anyone do something like this? Looking for help on google all the morning but didnt find any. Can anyone help me out there? Pleaseeeeeeee...

+1  A: 

These fields are automatically handled by propel. Simply unset() the fields in the form, and let propel do the magic :)

If you're using doctrine, add the Timestampable behavior to your class and unset the fields in the form, and it'll work too.

Maerlyn
but i am using doctrine, should doctrine also do the magic?
sparrow
I'm a propel guy, but as far as I can tell reading the Timestampable behavior's documentation, yes. See http://www.doctrine-project.org/documentation/manual/1_2/en/behaviors#core-behaviors:timestampable
Maerlyn
@sparrow, @maerlyn is right — you just have to unset these fields and Timestampable template will do the job for you. I'm fellow Doctrine user for last 1.5 years :)
develop7
@maerlyn, how about updating your answer so @sparrow could mark it as right one?
develop7
@all, thanks for helping. yes it worked also for doctrine. what i have learnt here is the created_at and updated_at must be created by symfony by actAs: Timestampable, not by hand directly in database. Thanks a lot again to all.
sparrow
Timestampable behavior works both using Doctrine or Propel, 100% guaranted !
Clement Herreman