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 -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -