I want to add check for more than one values in where clause. Db_RecordExists just check for one filed. I have read that you can extend zend validate abstract class and you can have your own validator. can I have one little example about this please.
Thank you...
What are you trying to do exactly? To me, you don't even need a custom validator.
If you read carefully the source code of
Zend_Validate_Db_Abstract
you will notice this phpDoc above the constructor:Which means that if you want to check if a record exists using more than one value, you can do it simply in passing the where clause to the validator instead of a pair field/value:
This will basically check if a record exists in the users table, and exclude rows where user id != 110 or email@example.com. Naturally, I recommend you to use Zend_Db methods such as
quoteIdentifier()
in order to generate a fully escaped query expression.You can add as many fields as you want of course.
You can find more information about
Db_NoRecordExists
in the documentation.All you usually have to do is override the isValid() method to make a custom validator,
here is an example of a custom validator:
}
Db_RecordExists is pretty simple but it extends
Zend_Validate_Db_Abstract
and should be pretty easy to modify to validate against two fields, but you may have to overrideisValid()
andgetSelect()
or_query()
to accept more then one value.