How do I get the value of a field before it was updated?

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

How do I get the value of a field before it was updated?

Postby rlevin » Tue Oct 18, 2011 11:20 am

I'm using the function beforeSave(), In my case I need to get a reference of the value of a field before the save button was clicked. I used $record->val("fieldhere"), but that gives me the updated value rather than the value before it was updated. I need it to compare the value before it was updated to after the field was updated.

I was thinking, creating a function that accepts the value of the field in one of your functions before the beforeSave() occurs then call that custom function in beforeSave() to return the value to compare to the updated field. I'm not sure if this is the correct way to handle this. If I did do it this way I'm not sure which function to use to retain the value in.

beforeAddExistingRelatedRecord?
beforeAddNewRelatedRecord?
beforeAddRelatedRecord
beforeCopy
beforeDelete?
beforeRemoveRelatedRecord?
beforeSave
beforeInsert?
beforeUpdate?
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am

Re: How do I get the value of a field before it was updated?

Postby shannah » Tue Oct 18, 2011 11:39 am

You can use the Dataface_Record::getSnapshot() method to get the records as they were before they were changed.

e.g.
Code: Select all
$snapshot = $record->getSnapshot();
$oldVal = $snapshot['myfield'];
$newVal = $record->val('myfield');


This is used in the methods
valueChanged() and recordChanged() to be able to tell if a field has changed or the whole record has changed since it was last saved.

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: How do I get the value of a field before it was updated?

Postby rlevin » Thu Oct 20, 2011 7:11 am

Thank you!
rlevin
 
Posts: 32
Joined: Thu Mar 10, 2011 11:40 am


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 19 guests

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