DataMapper


Automated Timestamps

DataMapper has the ability to automattically manage your Created and Updated timestamps, if your tables have the Created and Updated fields. By default, DataMapper looks for fields names created and updated. If they exist, it looks after the values for these fields without you ever needing to set them.

Note: By default, the Created and Updated fields are of the DateTime type, and GMT/UTC time is used.

If you would like to change the name of the Created and Updated fields, you can do so by setting the $created_field and $updated_field class variables in your DataMapper model. For example, we'll set them in our User model:

If you'd prefer to use Unix Timestamps or if you'd like to use Local Time instead of GMT/UTC, you can do so by setting the $unix_timestamp and $local_time class variables respectively. FOr example:

Alternatively, you can set this up globally for all your DataMapper models by setting them in the Configuration.