CakePHP3: Check if record exists

Here is a handy way to do it:

To check by primary key:


if ($this->Users->exists($id)) {
}


To find by specifying where clause:


if ($this->Users->exists(['email' => $email])) {
}


Much more convenient than using find('count').
#cakephp3

People Who Wowed This Post

×
  • If you are a bloguru member, please login.
    Login
  • If you are not a bloguru member, you may request a free account here:
    Request Account