2017-03-06 11 views
0

私はZend Framework 3を使用していますが、コレクションフィールドを持つフォームを検証しようとしています。Zend Frameworkコレクションの検証

私のフォームは、私は、フォームを送信すると

$this->add([ 
    'name' => 'domains', 
    'options' => [ 
     'target_element' => [ 
      'type' => Text::class 
     ] 
    ], 
    'type' => Collection::class 
]); 

が、私は以下の

のような CollectionInputFilterでこれを検証しようとしています POSTデータ

[ 
    'domains' => [ 
     0 => 'first' 
     1 => 'second' 
    ] 
] 

として、このような何かを得る場を持っています

$filter = new InputFilter(); 
$filter->add([ 
    'type' => CollectionInputFilter::class, 
    'options' => [ 
     'input_filter' => [ 
      'validators' => [ 
       [ 
        'name' => Hostname::class 
       ] 
      ] 
     ] 
    ] 
], 'domains'); 

$filter->setData($data); 

しかし、私は例外Zend\InputFilter\CollectionInputFilter::setData expects each item in a collection to be an array or Traversable; invalid item in collection of type string detected

私は間違っていますか?

答えて

1

エラーがCollectionInputFilterを使用していることがわかりました。代わりにArrayInputを使用していたはずです。