Zend Framework

Using class constant in the metacommand messages throw an exception

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Not an Issue
  • Affects Version/s: None
  • Fix Version/s: 1.8.0
  • Component/s: Zend_Filter_Input
  • Labels:
    None
  • Fix Version Priority:
    Should Have

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

Activity

Hide
Thomas Weidner added a comment -

Assigned to Bill

Show
Thomas Weidner added a comment - Assigned to Bill
Hide
Marc Jakubowski added a comment -

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

Show
Marc Jakubowski added a comment - 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') ) );
Hide
Bill Karwin added a comment -

Changing to 'Unassigned'

Show
Bill Karwin added a comment - Changing to 'Unassigned'
Hide
Wil Sinclair added a comment -

This issue should have been fixed for the 1.5 release.

Show
Wil Sinclair added a comment - This issue should have been fixed for the 1.5 release.
Hide
Wil Sinclair added a comment -

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

Show
Wil Sinclair added a comment - This doesn't appear to have been fixed in 1.5.0. Please update if this is not correct.
Hide
Wil Sinclair added a comment -

Please evaluate and categorize/assign as necessary.

Show
Wil Sinclair added a comment - Please evaluate and categorize/assign as necessary.
Hide
Michael Mazza added a comment -

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

Show
Michael Mazza added a comment - Is there an ETA for this issue? I continue to get this error when attempting to customize Validation Error Messages
Hide
Benjamin Eberlei added a comment -

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.

Show
Benjamin Eberlei added a comment - 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.
Hide
Benjamin Eberlei added a comment -

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

Show
Benjamin Eberlei added a comment - @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.

People

Vote (2)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved:

Time Tracking

Estimated:
1d
Original Estimate - 1 day
Remaining:
1d
Remaining Estimate - 1 day
Logged:
Not Specified
Time Spent - Not Specified