Default User ID
Archived from the Xataface Users forum.
Byrhtwulf72 — Wed May 16, 2012 6:07 pm
Hi, is there a way for me to get a field from a table and set that as a default value for another field? What I want to do is get the ID of the user that’s currently logged in and use that as the default value for another field. I plan to do this in the delegate class for the table, like this,
function User_ID__default(){
return ‘0001’;
but I don’t understand what I’m supposed to return. Thanks for your help.
shannah — Thu May 17, 2012 9:34 am
You could either user the fieldname__default() method (as you have mentioned) or use the beforeInsert() method to set the value before the record is inserted.
e.g.
- Code: Select all
function beforeInsert($record){ $user = Dataface_AuthenticationTool::getInstance()->getLoggedInUser(); if ( $user ){ $record->setValue('user_id', $user->val('user_id') ); } }
Byrhtwulf72 — Thu May 17, 2012 6:24 pm
Thanks, that’s just what I was looking for.