0
votes

I'm using CakePHP 2.3.0 and I need to be able to use an object (Logger) everywhere in my applications (from controllers and models).

This object is created in the AppController like this :

<?php
App::uses('Controller', 'Controller');
App::uses('Logger', 'Lib');

class AppController extends Controller {
    public function beforeFilter(){
        $this->Logger = new Logger(APP.'webroot/logs');
    }
}
?>

This works fine for controllers, I can use this object from every controller of the application, this way : $this->Logger->...

But obviously, it doesn't work from a model (because models don't extends AppController).

So I need :

  1. to know how to access a controller attribute (Logger) from a model
  2. or another way to achieve this (creating a global object accessible everywhere), not using AppController->beforeFilter()

Thanks

1

1 Answers

0
votes

To put it bluntly what you are doing is absolute crap. Read the chapter on logging on the cakephp manual and see how to configure log streams and how to write to them.