Validation 如何始终在ZF2验证器中显示单个验证消息?

Validation 如何始终在ZF2验证器中显示单个验证消息?,validation,zend-framework2,zend-form,Validation,Zend Framework2,Zend Form,我有以下意见: private function addBirthdayElement() { return $this->add( array( 'type' => 'DateSelect', 'name' => 'x_bdate', 'options' => [ 'label' =>

我有以下意见:

private function addBirthdayElement()
{
    return $this->add(
        array(
            'type'       => 'DateSelect',
            'name'       => 'x_bdate',
            'options'    => [
                'label'             => 'astropay_birthday',
                'label_attributes'  => array(
                    'class' => 'astropay-label'
                ),
                'create_empty_option' => true,
                'render_delimiters' => false,
            ],
            'attributes' => array(
                'required' => true,
                'class' => 'astropay-input',
            )
        )
    );
}
它具有以下过滤器:

public function addBirthdayFilter()
{
    $time = new \DateTime('now');
    $eighteenYearAgo = $time->modify(sprintf('-%d year', self::EIGHTEEN_YEARS))->format('Y-m-d');

    $this->add(
        [
            'name'       => 'x_bdate',
            'required'   => true,
            'validators' => [
                [
                    'name'                   => 'Between',
                    'break_chain_on_failure' => true,
                    'options'                => [
                        'min'      => 1900,
                        'max'      => $eighteenYearAgo,
                        'messages' => [
                            Between::NOT_BETWEEN        => 'astropay_invalid_birth_date_18',
                            Between::NOT_BETWEEN_STRICT => 'astropay_invalid_birth_date_18',
                        ]
                    ]
                ],
                [
                    'name'                   => 'Date',
                    'break_chain_on_failure' => true,
                    'options'                => [
                        'messages' => [
                            Date::INVALID      => 'astropay_invalid_birth_date',
                            Date::FALSEFORMAT  => 'astropay_invalid_birth_date',
                            Date::INVALID_DATE => 'astropay_invalid_birth_date',
                        ],
                    ]
                ],
            ],
        ]
    );

    return $this;
}
但是,如果输入一个空日期,我会得到为以下内容定义的错误消息: 日期::无效的\u日期

但它不是被覆盖的。break_chain_on_failure适用于我定义的两个验证器,但默认的Zend消息始终存在。例如,在我的表单中,这是一个错误:

The input does not appear to be a valid date
astropay_invalid_birth_date_18

如何一次仅显示一条隐藏的错误消息和一条消息?

您可以在验证器配置中使用
消息
键,而不是
消息
数组来始终显示每个验证器的一条消息

例如,替换此:

'options' => [
    'messages' => [
        Date::INVALID      => 'astropay_invalid_birth_date',
        Date::FALSEFORMAT  => 'astropay_invalid_birth_date',
        Date::INVALID_DATE => 'astropay_invalid_birth_date',
    ],
]
关于这一点:

'options' => [
    'message' => 'Invalid birth date given!',
]