Adding a field for last modified by...
Posted:
Thu Feb 23, 2012 1:03 pm
by wisni1rr
This should be an easy one.
How can I make a field in a table auto update with the current logged in user after a record has been created/modified?
Thanks again and again and again!!!
Re: Adding a field for last modified by...
Posted:
Thu Feb 23, 2012 1:20 pm
by wisni1rr
I think I am looking for something like this...
- Code: Select all
class tables_GENERAL {
function beforeSave($record){
$record->setValue('LastModifiedBy',
//* I need the syntax to replace 'LastModifiedBy' with the current logged in username.
);
}
}
Re: Adding a field for last modified by...
Posted:
Thu Feb 23, 2012 1:24 pm
by ADobkin
I use the following:
- Code: Select all
function beforeInsert(&$record) {
// Track creator
$user =& getUser();
$uid = getUserIDVal($user);
if ( $uid ) {
$record->setValue('creator', $uid);
$record->setValue('modifier', $uid);
}
}
- Code: Select all
function beforeUpdate(&$record) {
// Track modifier
$user =& getUser();
$uid = getUserIDVal($user);
if ( $uid ) $record->setValue('modifier', $uid);
}
For more details, refer to this post:
Record Tracking
Re: Adding a field for last modified by...
Posted:
Thu Feb 23, 2012 6:03 pm
by wisni1rr
Thanks a lot!
Your link to a previous thread was most helpful.
Rich