Automatically Insert Unixtime to a field.

A place for users and developers of the Xataface to discuss and receive support.

Automatically Insert Unixtime to a field.

Postby neotrode » Wed Jan 05, 2011 10:58 am

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
neotrode
 
Posts: 26
Joined: Mon Dec 20, 2010 11:08 am

Re: Automatically Insert Unixtime to a field.

Postby shannah » Fri Jan 14, 2011 12:38 pm

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());
    }
}
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 18 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved