Make a difference between insertion and update

If you want to make a difference between insertion and update in your model, e.g. in your beforeSave() function, you can test if the id of the model is not null:

function beforeSave()
{
    if ($this->id == null)
    {
        // it is an insert, do something
    }
    else
    {
        // it is an update, do something
    }			
    return true;
}

Thanks to gwoo for the hint, and to Frederic Logier (aka fredix) for his questions.

Post a Comment

Required fields are marked *
*
*

%d bloggers like this: