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

Issue Type: Bug Created: 2007-09-07T07:59:09.000+0000 Last Updated: 2009-01-07T16:27:30.000+0000 Status: Resolved Fix version(s): - 1.8.0 (30/Apr/09)

Reporter: Laurent Melmoux (laurent melmoux) Assignee: Benjamin Eberlei (beberlei) Tags: - Zend_Filter_Input

Related issues: Attachments:


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.

<pre class="highlight">
// 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')  )    


Posted by Thomas Weidner (thomas) on 2007-09-08T12:12:32.000+0000

Assigned to Bill

Posted by Marc Jakubowski (octavian) on 2007-10-02T17:01:00.000+0000

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') )

Posted by Bill Karwin (bkarwin) on 2007-10-17T15:28:44.000+0000

Changing to 'Unassigned'

Posted by Wil Sinclair (wil) on 2008-03-21T17:05:33.000+0000

This issue should have been fixed for the 1.5 release.

Posted by Wil Sinclair (wil) on 2008-04-18T13:12:06.000+0000

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

Posted by Wil Sinclair (wil) on 2008-04-18T16:58:29.000+0000

Please evaluate and categorize/assign as necessary.

Posted by Michael Mazza (dexthageek) on 2008-05-09T08:45:10.000+0000

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

Posted by Benjamin Eberlei (beberlei) on 2009-01-07T16:20:57.000+0000

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:

<pre class="highlight">
$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.

Posted by Benjamin Eberlei (beberlei) on 2009-01-07T16:27:16.000+0000

@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.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.