Page 1 of 1

Automatically Insert Unixtime to a field.

PostPosted: Wed Jan 05, 2011 10:58 am
by neotrode
Hello all.

The existing "timestamp=insert" call in the fields.ini file is very useful. However, I would like to do something just like this but with a unixtime timestamp instead. Basically, I have a field in the db set to int(11). In it, I want to store the current "time()" from PHP when a record is inserted. What's the best approach? At first, I was going to look into the Xataface code itself and add a new option like "unixtimestamp=insert" but I hate hacking at the original code in case I decide to do an upgrade. How can I handle this on the application/folder side?

-Frank

Re: Automatically Insert Unixtime to a field.

PostPosted: Fri Jan 14, 2011 12:38 pm
by shannah
The best way is probably to use a beforeInsert() method in the delegate class.

Code: Select all
function beforeInsert($record){
    if ( !$record->val("time_created") ){
        $record->setValue('time_created', time());
    }
}