I have a registration form in which users can fill in two email address (email1 & email2). Marketing\'s requirement is that they need to be unique (unique as in if we ha
At the risk of being beaten about the head and shoulders for offering a non-CakePHP solution, let me present the following.
Create a unique index in your database over however many columns you need.
Standard SQL syntax for this is:
create unique index {IndexName} on {Table} ({Column}, {Column}, ...)
Place your "$this->Model->save()" command inside of a "try/catch" block. In the "catch" block, test the exception for the error code. In MySQL, a unique key violation is error code 23000, but you should be prepared for other possible errors as well.
It's quick and simple and doesn't involve counting array parentheses.
You should always place database access code inside a "try/catch" block anyway. Part of your exception handling should include logging any unexpected error messages. You can't expect CakePHP to do everything for you.