php - aftersave() and beforesave() with dirty attributes -


i'm new yii2. i'm stuck in point of triggering changed attributes in update. need changed attributes , save table record changed new value.

please 1 me solve before save, after save , dirty attributes?

use getattributes() , getoldattributes methods in yii\db\activerecord. ie:

public actionupdate($id) {     $model = $this->findmodel($id);     if ($model->load(yii::$app->request->post())) {         $changed_attributes = array_diff_assoc($model->getoldattributes(), $model->getattributes());         if($model->save()) {             //save changed values in other table            //$changed_attributes contains attribute_name=>value pairs of changed(old) attributes. , $model contains new values.          }     } } 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

reflection - How to access the object-members of an object declaration in kotlin -

php - Doctrine Query Builder Error on Join: [Syntax Error] line 0, col 87: Error: Expected Literal, got 'JOIN' -