Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to check if record exists in Cakephp 3?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 6.22k
    Comment on it

    How to check if record exists in Cakephp 3

     

    I am writing this blog for them who are learning Cakephp 3. This blog will going to help you to find the solution for checking if record exists.

    In Cakephp 2 we can check records which exist by using Model::hasAny . For Example:

     

    $conditions = array( 'User.id' => $this->Session->read('User.id'),
    'User.security_key' => $this->Session->read('User.key') );
    if ($this->User->hasAny($conditions)){
    //do something
    }

    In Cakephp 3.x  we can check if record already exists in the database by using exists. For Example:

     

    $userTable = TableRegistry::get('User');
    $exists = $userTable->exists(['name' => 'user', 'active' => false]);

     

    Thats all.

     

    Thanks for reading the blog.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: