preSave and postSave hooks in Phalcon Model
-
30-06-2021 - |
Question
I was checking the API and noticed that there are _preSave
and _postSave
protected methods that could be used as hooks. Is there something similar for update/delete?
I was thinking of the following
preSave -> fires before a Save (insert/update)
postSave -> fires after a Save (insert/update)
preInsert
postInsert
preUpdate
postUpdate
preDelete
postDelete
Any existing functionality that I can use?
La solution
Compatible with version 0.4.5
In PhalconPHP these hooks are effectively validation events.
class Robots extends Phalcon_Model_Base
{
function beforeSave()
{
if ($this->year < 0) {
echo "Year cannot be negative";
return false;
}
}
}
More information about validators
http://docs.phalconphp.com/en/latest/reference/models.html#validation-messages
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow