Page 1 of 1

Adding logged on user to a record

PostPosted: Thu Jan 10, 2013 7:41 am
by ngms27
I have a table Projects which has a 1 to many relationship with Notes.
I'd like to be able to add the logged on user to a field in Notes every time a new notes record is added.

i.e. Notes structure is currently

id
project_id
details

I'd change it to

id
project_id
details
user

Re: Adding logged on user to a record

PostPosted: Thu Jan 10, 2013 10:27 am
by shannah
Use beforeSave() or beforeInsert().

Code: Select all
function beforeSave(Dataface_Record $record){
    $username = Dataface_AuthenticationTool::getInstance()->getLoggedInUserName();
    $record->setValue('user', $username);
}

Re: Adding logged on user to a record

PostPosted: Fri Jan 11, 2013 6:19 am
by ngms27
Worked great thank you.