Binding objects to collections of the form #2553

zfbot opened this Issue Sep 28, 2012 · 6 comments

4 participants


Jira Information

Original Issue: ZF2-518
Issue Type: Bug
Reporter: krishna m
Created: 09/04/12
Assignee: weierophinney
Components: Zend\Form


        'type'    => 'Zend\Form\Element\Collection',
        'name'    => 'addresses',
        'options' => array(
            'count'                  => 2,
            'should_create_template' => true,
            'allow_add'              => true,
            'target_element'         => array (
                'type' => 'Admin\Form\AddressFieldset',

How to bind the values to the elements of the fieldset when using the collections to the fieldset address[0]['street1'], address[0]['street2'] .... kindly Let me know how can be this achieved


(Originally posted by: froschdesign on 09/04/12)

Code tags added.


(Originally posted by: froschdesign on 09/04/12)

Is this a question or a bug report?
For questions please use the [mailing lists|].


(Originally posted by: krishna m on 09/04/12)

I hope its a bug


This issue was ported from the ZF2 Jira Issue Tracker at

Known GitHub users mentioned in the original message or comment:
@weierophinney, @froschdesign


Well, I had the same problem...

It looks coming from Zend\Form\Element\Collection extract method :

The method transforms the given object in array but the problem is that it is doing this recursively :

Zend/Form/Element/Collection: l.470

$this->object = ArrayUtils::iteratorToArray($this->object);

So when it try to extract object from the given collection, there are already converted in array :

Zend/Form/Element/Collection: l.473

$values[$key] = $this->targetElement->extract();

And it does not return nothing

the bug could be resolved by adding "false" as "recursive" argument of the ArrayUtils::iteratorToArray method :

Zend/Form/Element/Collection: l.469

if ($this->object instanceof Traversable) {
      $this->object = ArrayUtils::iteratorToArray($this->object, false);

Hope this could help


@netelix @krishnam is this solved by #3373 ?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment