ZF-1916: Using class constant in the metacommand messages throw an exception

Description

If we use a class constant in the metacommand messages a Zend_Validate_Exception exception is thrown with message 'No message template exists for key 'notBetween'.

This use case is actually not implemented in the Zend_Filter_Input class.


// Works
$validators = array(
    'month'   => array('Int', array('Between', 1, 12), 'messages' => array (0 => 'doit être compris entre 1 et 12')  )    
); 

// does not work
$validators = array(
    'month'   => array('Int', array('Between', 1, 12), 'messages' => array (Zend_Validate_Between::NOT_BETWEEN_STRICT => 'doit être compris entre 1 et 12')  )    
); 

Comments

Assigned to Bill

I get the same Exception if I want to set an error message for a custom validator rule that has an empty $_messageTemplages variable. It left it empty because the the validator needs a custom message per use-case, so I wanted to define it manually:

$validators = array( 'month' => array(new Custom_Validate_Object, 'messages' => array (0 => 'Wrong input') )
);

Changing to 'Unassigned'

This issue should have been fixed for the 1.5 release.

This doesn't appear to have been fixed in 1.5.0. Please update if this is not correct.

Please evaluate and categorize/assign as necessary.

Is there an ETA for this issue? I continue to get this error when attempting to customize Validation Error Messages

I have looked into it and i can only say that the problem is that you are using two validators instead of one like in the ZF manual example.

@Laurent: You have to modify your example the following way to get it working:


$validators = array(
    'month'   => array('Int', array('Between', 1, 12), 'messages' => array(1 => array(Zend_Validate_Between::NOT_BETWEEN => 'doit être compris entre 1 et 12')  )
));

The first key 1 indicates that the message belongs to the Between validator, the second array maps the message keys to the translations.

@Marc Jakubowski @Michael Mazza Your use cases are not supported by Zend_Validate_Abstract, you have to overwrite at least setMessage() in your custom validator to get it working correctly.

Instead i would suggest to implement a default message and still overwrite it all the time, works perfectly then. The problem with specifying no message at all is that specifying no failure tries to find the first messageKey and throws that message regardless of which failure occured. But without message keys an exception is thrown. This hinders your ways of customizing messages.