views:

25

answers:

1

Hi!

I´m trying to write a log system for my CakePHP intranet. What i need is to store de username/datetime whene someone tryes to login.

My login code is on the clients_controller and i need to store the data on a model called log (i have the model, controller, view... but they are not related)

how can i achive that?

thank you

+1  A: 

Add this line in your Client Controller:

$var uses = array('Client', 'Log'); // all the model that is used 
                                  // by the client controller. 

To create a log when someone logs in:

    $this->Log->create();
    $log = array('Log' => array(
      'username' => $username, 
      'datetime' => date('Y-m-d H:i:s') 
   )); 
   $this->Log->save($log); 
Sunny
Putting the Log model in the `$uses` array will load it for all actions in that controller. If you only need it for one action, you can load it manually using `$this->Log = ClassRegistry::init('Log');` inside your action.
deizel
Oh! that´s it? i´ll try later.thank you so much!
ikerib
ey! thany you two so much! it works!!
ikerib

related questions