在Zend Framework2中验证集合 [英] Validating Collections in Zend Framework2

查看:98
本文介绍了在Zend Framework2中验证集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

people ..
我的问题是:

people.. My problem is:

我有一个表单,有一个集合,所以,我设置了一个CollectionInputFilter到这个集合..

I have a form, with a Collection, so, I setted a CollectionInputFilter to this Collection..

如果我发送两个字段(集合)块来验证,并且该块之一的一个字段被验证,则另一个块中的相同字段也被自动验证,即使是错误或没有填补..
我不知道该怎么办..我尝试了很多提示..但是,没有工作..

If i send two block of fields (collections) to validate, and one field of one of this block is validated, the same field in the another one block is automatically validated too, even if is wrong or not filled.. I don't know what to do.. I tried a lot of tips.. but, none worked..

有人可以帮助我吗?还是面临同样的问题?

Someone can help me? Or faced the same problem?

这里我的代码:

class ClienteEnderecoFilter extends CollectionInputFilter
{
 public function __construct()
    {
$this->add(array(
            'name' => 'fieldOne',
            'required' => true,
            ));

}
}



如果我发送两个fieldOne

If i send two fieldOne and one is filled, the another one is validated too!

我认为你需要为每个集合项设置输入过滤器,这样就可以对每个集合项设置输入过滤器了。

解决方案

推荐答案

use Zend\InputFilter\InputFilter;

class ClienteEnderecoFilter extends InputFilter
{
    public function __construct()
    {
        $this->add(array(
            'name' => 'fieldOne',
            'required' => true,
        ));

    }
}

$collectionInputFilter = new CollectionInputFilter();
$collectionInputFilter->setInputFilter(new ClienteEnderecoFilter());

这篇关于在Zend Framework2中验证集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆