Yii 1.1: ac-audit-trail

Super classes that allow an audit trail to be built automatically for subclasses + nested transactions

This extension will allow models to be backed up by an audit trail. It also creates the functionality of nested transactions (MySQL tested).




  • Yii 1.0 or above


  • Extract the release file under protected/extensions (usually I use components, but extensions should be fine)
  • File list: AuditedCActiveRecord --- extend from this class if you want the subclass to be backed by the audit trail AuditTrail --- the model describing the audit trail table AuditTrailSequenceNumber --- the model describing the audit trail sequence table CustomCActiveRecord --- the base class for all models NestedCDbConnection --- creates/supports nested transactions NestedTransactionPDO --- creates/supports nested transactions


  • Modify config/main.php -> db array to use class=>NestedCDbConnection
  • Import audit_schema.sql (MySQL)


For the required model, extend from AuditedCActiveRecord. Save/delete as per normal. If transactions are desired, use transactedSave/transactedDelete.

Classes which want to use transatedSave/transactedDelete must extend from CustomCActiveRecord.

Read the comments in the classes for more information!

Change Log

July 1, 2010

  • Initial release.

Total 2 comments

#347 report it
johocn at 2010/07/02 08:04am
transactions not rollback

$model=new Tsql; for($i=14;$i>10;$i--){ $model->id=$i; $model->uo=$i; $model->po=$i; $model->transactedSave(); echo $model->uo.'='.$model->po; } 如上列,假如我数据中有id为11的记录,则报错,最后一条成功数据id为12的记录,不会rollback,其他的id为14,15的两条记录rollback成功

#354 report it
johocn at 2010/07/01 10:18am

以下语句如何写? protected function afterSave() { if(!$this->isNewRecord) $this->dbConnection->createCommand( 'DELETE FROM PostTag WHERE postId='.$this->id)->execute();

foreach($this->getTagArray() as $name)
        $tag=new Tag(array('name'=>$name));
        "INSERT INTO PostTag (postId, tagId) VALUES ({$this->id},{$tag->id})")->execute();


Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: Other Open Source License
  • Developed by: Angelystor
  • Category: Database
  • Votes: +1
  • Downloaded: 745 times
  • Created on: Jul 1, 2010
  • Last updated: Jul 1, 2010