I have the bellow login function in my controller and am trying to save the login date/time into the users database table under the field last_login that is a DATETIME field, login works fine but the field never gets populated.. any ideas on what may be stopping this or how to troubleshoot what should be getting output?
public function login() {
$this->layout = 'login';
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->User->id = $this->Auth->user('id'); // target correct record
$this->User->saveField('last_login', date(DATE_ATOM)); // save login time
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash('Invalid username or password, try again', 'default', array('class' => 'warning'));
}
}
If your last_login field in db is set to
DATETIMEthen, you need to do:As
DATE_ATOMreturns something like2012-08-15T15:52:01+00:00, so it wont get insertedTry disabling AuthComponent::autoRedirect, like