Vito Vito - 4 months ago 7x
PHP Question

Logging on CakePHP2

I'm working on a cakePHP 2 system which have a logging section that records which data was saved by the users, for example:

The user: A save on database_table the following data:
complete_name: B
description: something

There is a logs table that have the following fields: id, users_id, date and description

Every time a user saves data, a new row is generated on the logs table. This process is done automatically, no controller have code to save on that table, so I assume that there is some CakePHP feature that is doing this.I need to do some modifications, but I cannot find where I can configure that logging feature. I was reading the CakePHP documentation at, but I cannot find the setting.

Someone know where is this feature located and how can I modify it?


I found a solution based on the comment provided by ndm. The code for this is on the afterSave event of the AppModel, which is extended to all the other models. The code on the AppModel looks like this one:

App::uses('Model', 'Model');

 class AppModel extends Model {

public function afterSave($created, $options = array()) {
    $data = $this->data;
    //if the value its != de Statisctic excutes regular code

    if( ! isset($data['Statistic'] ) ){
            if((isset($_SESSION['User']['User']['id'])) && ($_SESSION['User']['User']['id'] != null)){
                //here goes all the logic which saves to the logs table                    


Since this model will be extended to all the other models, this code runs after every save on the database.