Help needed to created a log in models methods

Hi everybody.

I want in my admin models to monitor and log every action executed.

Something like:

  • User A added a new product

  • User B removed User C for reason spamming

  • Product X sold.

In briefing, I don't need to undo actions done. But I wanted all logged (in a table).

How can I achieve this with Yii?

Create a behavior?

Saves this logs by model methods?

Saves this logs by controller methods? (actions)

Maybe this could be a component for everyone.

Can someone show me the path for rightousness?

Yeah, a behavior should be fine. You mainly need to handle afterSave and afterDelete.

Thanks  ;D

Hi Ismael and others,

did you meanwhile succeed with this issue? Probably having a component doing this??

I’m thinking of implementing a kind of command-pattern. It stores a command object in a active-record model on each manipulating record.

Later you can look to the list of commands, look what they have done and what was the value before.

Of course, it should also be possible to undo the commands in reverse order step-by-step and undelete or unmodify what was changed.

But this is only an idea, maybe you are somehow further with any solution…

Thanks in advance

Achim