This week, I’ve worked in PHP project based in Yii framework version 2. As a consequence, I had to build a class which can register the transaction processes in an extended class of ActiveRecord. The condition was, “Don’t touch the core code of YII2”. So, I created my own class that extends from ActiveRecord (it called AuditActiveRecord) and I will explain how it works:

  • First, I created a model class which will register three transactions, like Insert, Update and Delete. This class called Log.
  • Second, I made a class that extend from ActiveRecord and revoke these functions: afterSave and afterDelete.
  • Last, apply and extend from this class in your other model classes.