Php zend验证消息未显示

Php zend验证消息未显示,php,zend-framework,Php,Zend Framework,下面的代码没有显示验证消息,我应该在任何地方打印任何变量。请告知 $username = new Zend_Form_Element_Text('username', array('autocomplete' => 'off')); $username->setLabel('Username') ->setDecorators($elementDecoration) ->setRequired

下面的代码没有显示验证消息,我应该在任何地方打印任何变量。请告知

$username = new Zend_Form_Element_Text('username', array('autocomplete' => 'off'));
        $username->setLabel('Username')
                ->setDecorators($elementDecoration)
                ->setRequired(true)
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty', true, array('messages'=>'Cannot be empty'));


$elementDecoration = array(

            'ViewHelper',
            'Description',
            'Errors',
            array(array('data'  => 'HtmlTag'), array('tag' => 'td')),
            array('Label', array('tag' => 'td', 'placement' => 'prepend')),
            array(array('row'   => 'HtmlTag'), array('tag' => 'tr')),
        );
试试这个

$username->setLabel('Username')
                ->setDecorators($elementDecoration)
                ->setRequired(true)
                ->addErrorMessage('Cannot be empty')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');
确保使用的装饰器是正确的

$element->setDecorators(array(
    'ViewHelper',
    'Description',
    'Errors',
    array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div')),
    array(array('td' => 'HtmlTag'), array('tag' => 'td')),
    array('Label', array('tag' => 'td')),
));

您想从元素中删除
setRequired
函数。此函数正在覆盖
NotEmpty
验证程序。由于您正在检查
NotEmpty
,因此可以删除
setRequired
,以显示您自己的消息。

我想可能出现了一些问题,因为setdecorators我只想在用户未输入时显示验证消息,但当前它显示“值是必需的,不能为空”在下一个字段中发送消息。如何仅在未输入用户时显示验证消息。请检查我的setDecorators