zf2的inputfilter

'

使用语句(注,此处重点在于说明数据校验):

$inputFilter->add($factory->createInput(array(
                'name' => 'content',
                'require' => true,
                'filters' => array(
                    array('name'=>'StripTags','options'=>array()),//to remove unwanted HTML
                    array('name'=>'StringTrim'),//to remove unnecessary white space
                ),
                'validators' => array(
                    array(
                        'name' => 'StringLength',
                        'options' => array(
                            'encoding' => 'UTF-8',
                            'min' => 1,
                            'max' => 250,
                        ),
                    ),
                ),
            )));

'name':input标签的名称

'required':是否是必须输入框

'allow_empty':是有允许空

'fallback_value':如果转换失败的默认值

'type' => class:可以跟在new语法后边的完整语法字符串,表示一个自定义的落滤器类型。默认值为Zend\InputFilter\Input

filters:过滤器(value可以是FilterChain or array(object or callable, ...) or array(array()),下边是array可以设置的内容):

    StripTags:转义html标签

    StringTrim:去掉首尾空格

    Int:去掉非整形数据    

    ... ...(各种filter类,在\Zend\Filter里面,也可以自己扩展)


validaters:校验器(取值范围:ValidatorChain or array(ValidatorInterface的实现类,...)  or array(array()):

    StringLength:字符串长度

    ... ... (各种validator类,在\Zend\Validator里面,不过也可以自己扩展来满足自己的特殊需求)   



你可能感兴趣的:(PHP,zendframework2,zf2,数据校验,inputfilter)