DataMapper ORM


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:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php class User extends DataMapper { var $created_field = 'created_on'; var $updated_field = 'updated_on'; function __construct($id = NULL) { parent::__construct($id); } } /* End of file user.php */ /* Location: ./application/models/user.php */

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:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<?php class User extends DataMapper { var $created_field = 'created_on'; var $updated_field = 'updated_on'; var $local_time = TRUE; var $unix_timestamp = TRUE; function __construct($id = NULL) { parent::__construct($id); } } /* End of file user.php */ /* Location: ./application/models/user.php */

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

Timestamp Format

New to Datamapper ORM 1.7.0, you can now specify the timestamp format.