afterUpdate() ? it exist ?

hi,

is there an afterUpdate function implemented in yii ? i mean when i call $model->update(), is there an afterUpdate() that will be invoked lik afterSave() ?

Note : version is 1.1.5

Not really, so you might need to use CActiveRecord’s getIsNewRecord() method in your beforeSave() method and set a flag that can be called during afterSave(). You will have to use a flag parameter as isNewRecord will always be false in afterSave()


public function beforeSave()

{

    if(!$this->isNewRecord)

        $this->updateFlag=true;

    return parent::beforeSave();

}


public function afterSave()

{

    if($this->updateFlag)

        //this model was updated

    

    parent::afterSave();

}

Well… in fact you do not need this flag. isNewRecord flag is updated during save AFTER calling afterSave, so you can just check $this->isNewRecord in afterSave.

Look at CActiveRecord::insert() if you want to be sure:

$this->afterSave();

$this->setIsNewRecord(false);

sorry but i think i found it.

No need to afterUpdate() function because when calling $model->update() it already invoke the aftersave() function, i saw it in the code of the update function in the CActiveRecord

Ah, wasn’t sure about that. Thanks for pointing it out!