overriding cactiverecord update method in models

Hi - new to Yii so please forgive any apparent stupidity :)

I have a large number of models. I would like to override the parent class update method in the models so that I can manipulate the incoming data slightly before allowing the parent update method to do it’s stuff as normal. The manipulation I wish to perform is identical in every case and I am wondering if it is possible to avoid having to override the update method in each model individually and avoid changing the CActiverecord parent class which I guess would be a very bad thing to do. Do I really need to add an update method to each model or can this be done in some other way. The manipulation is something that would involve the use of another model to check that a incoming value lies within certain parameters which change over time so is not a simple ‘rule’.

Thanks very much for any help.

TB

You can extend CActiveRecord and let each model extend that class. But you don’t necessarily have to override update, you can also create a beforeSave function in each model, or in a behavior (and add this behavior to each model)

Cheers

Thanks for that - extending CActiveRecord makes sense. I will have to take a look at the beforeSave method later today - will have to find out if it fires just on a save or is also triggered before an update takes place. Have not yet looked at Yii behaviours so have no idea what they are and what they do - will add it to the list of ‘things I don’t unerstand in Yii’

Thanks again for the help…

This might be helpful:

http://www.yiiframework.com/wiki/121/extending-common-classes-to-allow-better-customization/

thank you steve - interesting :)