columns with automatic content

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

Postby ckkart » Mon Oct 01, 2007 12:20 am

Hi,

I'm looking for a way to have dataface fill columns holding username, timestamp, etc. automatically. I haven't yet read all of the documentation - could anybody point me to the right place to look for?

Christian
ckkart
 
Posts: 1
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Mon Oct 01, 2007 7:52 am

You can use the beforeInsert() trigger:
http://framework.weblite.ca/documentation/tutorial/getting_started/triggers

Note.. I recommend you read at least the first 5 or 6 sections of the getting started tutorial if you want to start building with dataface. It doesn't take too long and it should give you some good background on what you need to do.

e.g.:

function beforeInsert(&$record){
$record->setValue('username', 'some username');
}


or even better

function beforeInsert(&$record){
$auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();
if ( $user ){
$record->setValue('username', $user->val('username'));
}
}


For the timestamp, you can either use a MySQL timestamp field to have mysql do it for you automatically, or you can use a datetime field and use the 'timestamp' directive in the fields.ini file.

e.g.

[mydatefield]
timestamp=insert

or

[mydatefield]
timestamp=update

-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
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 28 guests

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