afterSave not saving

Hi I just want to ask, I am getting the sum from the two of my textfields,but unfortunately it did not save to my table in column amount.can you help me why is not saving please.

Thank you in advance.

payment.php //this is my model extends CActiverecords







protected function afterSave(){

  parent::afterSave();


  $this->amount =   $->txt1 + $this->txt2;


}




You need $this->save() there, but without an additional mechanism it would make infinite loop.

May I ask why you are trying to save your model again right after saving it for the first time with slightly different data?

Assuming all the attributes belong to $this. Why not change the $this->amount and save it with everything once?

afterSave is called AFTER save, so any data manipulation is pointless here.

use beforeSave if you want that data to be saved.

protected function beforeSave(){

$this->amount = $->txt1 + $this->txt2;

return parent::beforeSave();

}

@Bizley,

The reason I want is that I have form like this

txt1

txt2

other txtfields…

Now the amount is automatically computed when clicking the save button…I have no amount textfield in my form.

Maybe I am wrong in using the afterSave(); my understanding for this is when all the data is finished inserted the afterSave will be invoke and I can do insertion again in other column that what I want.

Okay I will try this beforeSave,by the way do I still call the $this->save() inside beforeSave ?

@redguy,

Thank you it works :) …Thank you also for all the inputs who helped me :)