I have a last_login field in my user model and I needed to update it whenever the user would login. Of course cakephp should make thisÃ‚Â ridiculouslyÃ‚Â easy and straightforward, you know, a single call to updateField would be nice, but that doesn’t exist. So here’s how to update a single field with a datetime type (mysql) using something that does exist in cakephp.
$this->User->updateAll( array("User.last_login" => "'".date(DATE_ATOM)."'"), array( "User.username" => $this->data["User"]["username"] ) ); // Updates last_login with a mysql datetime compatiable string, it must be mannually escaped because Cake PHP didn't think it would be smart to let it handle it.
So basically the code above updates last_login with date(DATE_ATOM), which I encourge you to try out as it makes a mysql datetimeÃ‚Â compatibleÃ‚Â string. It looks up the correct user to update via the username.
I’m not sure why cakephp didn’t have a method like saveField for updateField. It would be way too easy. Doing this makes me feel dirty.