cakephp - Save without updating the 'modified' field -
i'm working on new project using cakephp 3.0.
i'm using authentication component , whenever user logs in, i'm updating value of field visited
.
userscontroller:
public function login() { if ($this->request->is('post')) { $user = $this->auth->identify(); if ($user) { $this->auth->setuser($user); $this->users->setvisited($user['id']); return $this->redirect($this->auth->redirecturl()); } $this->flash->error('your username or password incorrect.'); } }
userstable:
public function setvisited($id) { $user = $this->findbyid($id)->first(); $user->visited = time::now(); if($this->save($user)) { return true; } return false; }
now, save without updating value of field modified
. i've tried approach used in previous versions of cake:
$user->modified = false;
it doesn't work though, throwing , error: call member function format() on non-object
because datetime fields treated objects guess.
any appreciated,
paul
you have couple ways of doing this. want avoid calling callbacks when saving entity. cases have updateall
$this->updateall(['visited' => time::now()], ['id' => $id]);
you can same before, need disable timestamp behavior before saving:
$this->behaviors()->unload('timestamp');
i recommend using updateall
Comments
Post a Comment