Building an audit engine with Zend Framework
Part of what I love with ZF is the ease at which I can extend it to do what I need.
For instance, recently I was developing my app (codenamed Karmba) - something I needed to do is to be able to log every transaction, and at any time restore a version of information.
Let’s say for instance, that I have a blog - I know, I know, everyone uses that as an example, but let’s stick with something familiar, okay - and within my admin, I want to edit an entry. I start with my controller.
Disclaimer: This post is based on a real application, but isn’t all of the actual code. It is not plug and play; expecting this code to work out of the gate does not reflect what I’m trying to do.
For reference, DomainObject is just a convenience class - you can easily replace it with Zend_Db_Table
Now, let’s take a look at the Factory itself. A majority of this should be familiar to you.
Now, to illustrate my point, we create an object, Blog_Post - within Blog_Post there’s as much or as little as we need to alter the data.
Fanatic programmer, obsessive technophile, serial entrepreneur and Web 2.0 enthusiast. Zed23.com is the personal blog of Ryan Brooks, a Web Application Developer out of Calgary, Alberta.
Adam
April 3rd, 2008 at 8:25 am
Nice. So this would make a row in the _audit table for each column modified.
I plan on doing something like this for an Undo Manager in my web application. Thanks for the proof of concept!