Default User ID

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

Default User ID

Postby 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.
Byrhtwulf72
 
Posts: 9
Joined: Wed Feb 22, 2012 12:24 pm

Re: Default User ID

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

Re: Default User ID

Postby Byrhtwulf72 » Thu May 17, 2012 6:24 pm

Thanks, that's just what I was looking for.
Byrhtwulf72
 
Posts: 9
Joined: Wed Feb 22, 2012 12:24 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 15 guests

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