I'm using PHP (Yii-framework) and MySQL database on my site.
Users can post and edit some articles. How can I store every edit version like here in SO? (Like Wikipedia, this site is collaboratively edited, and all edits are tracked)
What sould I use and how? Database structure? Some libraries? What keywords should开发者_JAVA百科 I use to google? :)
UPD. And how to display changes between revisions, like here in SO?
Thanks
I'd use your current database structure (if you have one, otherwise make one with all the fields you need), but add 1 or two extra columns, the most important being the revision number. This can simply be incremented each time a revision is made. This can be tricky to code cleanly into the database INSERT
command (note, use INSERT
not UPDATE
because you want to keep the old post).
Another way would be to have a column storing the time the update was submitted (maybe just "created time"?), and from that you can glean how many updates there have been (count the rows), and what order they are in (order by date).
You're looking for a PHP ORM with audit logging capabilities. What is the ORM embedded within Yii framework?
I know that Symfony uses Doctrine and has a dedicated Versionable Plugin that does exactly what you want.
Maybe the "logable_behavior" Yii skeleton can help you.
精彩评论