, , ,

Sometime we may need auth data for inserting in bforeSave method, i know it break the MCV rule but we sometime we need it for doing faster.

I used it in beforeSave method in a module

function beforeSave(){
   App::import('Component', 'SessionComponent'); 
   $session = new SessionComponent(); 
   // say we just retrieve the auth data
   $auth = $session->read("Auth.user");
  // here i used to add row value
  $this->data['ModelName']['field_name'] = $auth['login_user_id'];
  return true;

In this way we can use full session component data here. 🙂