Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6112963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:48:16+00:00 2026-05-23T14:48:16+00:00

(New to CakePHP, so this may be an obvious thing, but I was unable

  • 0

(New to CakePHP, so this may be an obvious thing, but I was unable to find a solution after searching for a couple of hours – the ambiguous nature of “or”, I guess…)

I am trying to modify an existing CakePHP validation rule, which uses the isUnique rule, so that it will validate for values which satisfy either the isUnique rule or an inList rule.

The previous code:

'isUnique' => array(
  'rule' => 'isUnique' ,
  'message' => "We're sorry, but this QA number is already being used.",
  'last' => TRUE,
),

My (faulty) code:

'isUnique' => array(
  'rule' => array( 
    'isUnique' ,
    array( 'inList' , array( '111213' , '141516' , '171819' , '202122' ) )
  ) ,
  'message' => "We're sorry, but this number is already being used.",
  'last' => TRUE,
),

So, (as simple as this may be), how can you string CakePHP validation rules together with an “OR” logical operator? I can see that you can apply a cascade of “AND” rules (with each testing for a specific issue and, if failing that test, rejecting the value), but “OR” rules have me scratching my head…

Any help appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:48:17+00:00Added an answer on May 23, 2026 at 2:48 pm

    You’ll have to make that a custom validation rule. Add this in your model:

    public function isUniqueOrInList(array $data, array $list) {
        return in_array(current($data), $list) || $this->isUnique($data);
    }
    

    Then declare your rule like:

    'rule' => array('isUniqueOrInList', array('111213', '141516', '171819', '202122'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realize this seems like an obvious JS type thing - but I'm new
This seems like it should be simple, but I'm new to CakePHP. Maybe it's
I'm new to cakePHP, so I may be missing the obvious. The system is
I'm new to CakePHP but I've been though their FAQs and guides to no
I'm new to CakePHP and am just running through the configuration process, but am
I'm pretty new to CakePHP but I think I'm starting to get the hang
How do you print a new line break in CakePHP. I have tried this
i'm very new to this cakephp & i got an assignment to fix an
Okay, so I'm fairly new to CakePHP. This is the setup: I've got a
I'm new to cakephp...and I have a page with a url this: http://localhost/books/filteredByAuthor/John-Doe so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.