我有以下输入过滤器使用验证但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',
),
),
),
),
));
答案 0 :(得分:0)
如果您检查Filter目录,您会看到其中有一些:
Zend/Filer/*
您应该使用过滤器文件名作为名称,这将在框架尝试包含Filter类时使用。
$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,
),
),
),
)));