Anyway... we do a lot of logging of record creation etc to the db for
various reasons and ideally a behavior is what your after, but for a quick
solution its easy enough to call the log model on the fly in your model
callbacks like
function afterSave($created) {
$action = $created ? 'create' : 'update';
$Log =& ClassRegistry::init('Log');
$Log->create();
$Log->save(array('action' => $action, 'model' => $this->name,
'foreignKey' => $this->id));
}
That's a pretty crude example but nothing wrong with doing it that way if it
fits your needs. If you were to be doing this in your app model to trigger
on all models, be sure to stop the callback on your log model save,
otherwise it will eternally log it self to death.
$Log->save(array('action' => $action, 'model' => $this->name, 'foreignKey'
=> $this->id), array('callbacks' => false));
HTH
Paul
-----Original Message-----
From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf
Of satyavirya
Sent: Saturday, 4 July 2009 4:18 a.m.
To: CakePHP
Subject: Write to log table for every successful update/delete
Hi guys, my app need to write into a log table for every successful
update/delete operation, my current approach is to put the code in
AfterFilter in AppController, the problem is, how do I get / know a
successful update/delete has been done?
Or is there any other suggestions to do this? Thanks.
__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4214 (20090703) __________
The message was checked by ESET NOD32 Antivirus.
__________ Information from ESET NOD32 Antivirus, version of virus signature
database 4215 (20090704) __________
The message was checked by ESET NOD32 Antivirus.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment