Sabtu, 14 Ogos 2010

CakePHP beforeSave :: Automatic append user_id

I use this callback extensively, so need to hardcode user_id in every controller.

function beforeSave() {
      App::import('Component', 'Session');
      $Session = new SessionComponent();
      $user = $Session->read('Auth.User');
      $this->data[$this->alias]['user_id'] = $user['id'];
      return true;
  }

Tiada ulasan:

Catat Ulasan