I am wondering how I would go about performing a certain function if a particular field in cakephp save has been updated.
function edit($id = null) {
if (!empty($this->data)) {
if ($this->Post->save($this->data)) {
$this->Session->setFlash(__('The post has been saved', true));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The post could not be saved. Please, try again.', true));
}
}
}
So – what I would like to do is be able to determine exactly what has been changed in the edit data ($this->data) and if a certain field has been changed send an email notification. I know how to do the email part – but can’t figure out how I would do it if lets say a select box was changed from Enabled to Disabled. If changed from enabled to disabled email saying blah blah blah has been disabled.
You can read out the current saved content before you execute $this->Post->save() and compare the values after saving.
As mark said, it would be cleaner to acomplish this direct in the model (e.g. in the case the data is changed in a different form)