framework/db/BaseActiveRecord.php
public function beforeSave($insert)
    {
        $event = new ModelEvent();
        $this->trigger($insert ? self::EVENT_BEFORE_INSERT : self::EVENT_BEFORE_UPDATE, $event);

        return $event->isValid;
    }
public function beforeSave($insert)
    {
        $event = new ModelEvent();
        $this->trigger($insert ? self::EVENT_BEFORE_INSERT : self::EVENT_BEFORE_UPDATE, $event);

        return $event->isValid;
    }
This method is called at the beginning of inserting or updating a record.

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)) {
return false;
}

// ...custom code here...
return true;
}
```

@param bool $insert whether this method called while inserting a record.
If `false`, it means the method is called while updating a record.
@return bool whether the insertion or updating should continue.
If `false`, the insertion or updating will be cancelled.