I have a Behavior which update a record instead of delete from beforeDelete
callback.
public function beforeDelete(Model $model, $cascade = true) {
[...]
return true;
}
When I return true
, the deletion proccess continues, instead of stop. I wan't to stop propagation of next event which is delete
.
I have read about stopPropagation()
function of CakeEvent
but don't know what to do and how to use correctly inside a behavior. May you help-me?
Taken from the CakePHP core libraries help page:
public function beforeDelete(Model $model, $cascade = true,$event) {
[...]
$event->stopPropogation();
}
That should do it.
If you want to stop the deletion you should return false in beforeDelete() callback instead of returning true. Check the documentation:
This function should return true if you want the deletion to continue, and false if you want to abort.
So your code should look like this:
public function beforeDelete(Model $model, $cascade = true) {
[...]
return false;
}