The default implementation will trigger an [[EVENT_BEFORE_INSERT]] event when $insert is true,
or an [[EVENT_BEFORE_UPDATE]] event if $insert is false.
When overriding this method, make sure you call the parent implementation like the following:
php
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
...custom code here...
return true;
} else {
return false;
}
}
public beforeSave ( boolean $insert ) : boolean | ||
$insert | boolean | whether this method called while inserting a record. If `false`, it means the method is called while updating a record. |
return | boolean | whether the insertion or updating should continue. If `false`, the insertion or updating will be cancelled. |