Latest Updates based on model updates

Hi all,

Im developing a site and owuld like to maintain a list of updates that have happened since a users last visit e.g.

Whats been happening:

28/11/11 14:00 - New member joined: Joe Boggs

28/11/11 14:00 - Fixture added

28/11/11 14:00 - Result updated

Table would contain something like UpdateDateTime, URL, Message.

Whats the best way to go about updating this table following model inserts/updates? I was thinking about raising an event (onUpdate) in the controller (which would populate the url, message etc in the event) and have a static function handle the updation of the latestUpdates table? Does this sound feasible? Had also though of using the afterSave handler but creating the URL from within the model doesnt seem right. Any recommendations if theres a better way to do this in Yii?

Many thanks for any help

Cheers

Ross

You can create a behavior and add it to models that will update that table…

Or you can create a base class like ActiveRecord that extends CActiveRecord with a method afterSave()… and extend from it all models that need to update that table…

Hi Mdomba,

Firstly thanks for replying. I had thought of using a behaviour but as i want to store a message and link for each save type e.g. New User added: <Username>, New fixture added: <Team> vs <Team> etc the behaviour wont know what type of update has occured and what fields (e.g. <Username>) it can obtain as well as what url to use? Or am i missing something?

Thanks

Ross

For this you can create a custom property in those models (public updateMessage;)… before saving you can assign the value you need to save… and in the afterSave you use the $model->updateMessage…