0

我有以下输入过滤器与验证一起使用,但 StringToLower 过滤器不起作用。有人知道这是如何工作的吗?Zend2 文档在我使用的编码方法中没有任何示例。

$this->add(array(
        'name' => 'cemail',
        'required' => true,
        'filters' => array(
            array(
                'name' => 'string_to_lower',
            ),                
            array(
                'name' => 'StringTrim',
            ),       
        ),
        'validators' => array(
            array(
                'name' => 'NotEmpty',
                'break_chain_on_failure' => true,
                'options' => array(
                    'messages' => array(
                        'isEmpty' => 'Email address is required'
                    ),
                ),
            ),
            array(
                'name' => 'EmailAddress',
                'break_chain_on_failure' => true,
                'options' => array(
                    'hostname' => true,
                    'messages' => array(
                        'hostnameInvalid' => 'Invalid email address provided.',
                    ),
                ),
            ),
            array(
                'name' => 'string_length',
                'options' => array(
                    'encoding' => 'UTF-8',
                    'min' => 5,
                    'max' => 150,
                    'messages' => array(
                        'stringLengthTooLong' => 'Email address must not exceed 150 characters',
                        'stringLengthTooShort' => 'Email address must contain at least 5 characters',
                    ),
                ),
            ),
        ),
    ));
4

1 回答 1

0

如果您检查过滤器目录,您会看到那里有一些:

Zend/Filer/*

您应该使用过滤器文件名作为名称,这将在框架尝试包含过滤器类时使用。

$inputFilter->add($factory->createInput(array(
        'name'     => 'my_field',
        'required' => FALSE,
        'filters'  => array(
            array('name' => 'StripTags'),
            array('name' => 'StringTrim'),
            array('name' => 'StringToLower'),
        ),
        'validators' => array(
            array(
                'name'    => 'StringLength',
                'options' => array(
                    'encoding' => 'UTF-8',
                    'min'      => 1,
                    'max'      => 45,
                ),
            ),
        ),
    )));
于 2013-08-20T10:13:45.777 回答