views:

68

answers:

1

Hello,

I have a model where I need to do some processing before saving (or in certain cases with an edit) but not usually when simply editing. In fact, if I do the processing on most edits, the resulting field will be wrong. Right now, I am working in the beforeSave callback of the model. How can I tell if I came from the edit or add?

Frank Luke

+2  A: 
function beforeSave() {
  if (!$this->id && !isset($this->data[$this->alias][$this->primaryKey])) {
    // insert
  } else {
    // edit
  }
  return true;
}
neilcrookes
Thank you. Worked perfectly.
Frank Luke