Each validator which is based on Zend_Validate provides
one or multiple messages in the case of a failed validation. You can use
this information to set your own messages, or to translate existing messages which a
validator could return to something different.
These validation messages are constants which can be found at top of each validator class.
Let's look into Zend_Validate_GreaterThan for an descriptive example:
<?php
protected $_messageTemplates = array(
self::NOT_GREATER => "'%value%' is not greater than '%min%'",
);
As you can see the constant self::NOT_GREATER refers to the failure and
is used as key, and the message itself is used as value of the message array.
You can retrieve all message templates from a validator by using the
getMessageTemplates() method. It returns you the above array which
contains all messages a validator could return in the case of a failed validation.
<?php
$validator = new Zend_Validate_GreaterThan();
$messages = $validator->getMessageTemplates();
Using the setMessage() method you can set another message to be
returned in case of the specified failure.
<?php
$validator = new Zend_Validate_GreaterThan();
$validator->setMessage(
'Please enter a lower value',
Zend_Validate_GreaterThan::NOT_GREATER
);
The second parameter defines the failure which will be overridden. When you omit this parameter, then the given message will be set for all possible failures of this validator.




