Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Binding objects to collections of the form #2553

Closed
zfbot opened this Issue · 6 comments

4 participants

@zfbot
Owner

Jira Information

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

Description

$this->add(
    array(
        '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

@zfbot
Owner

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

Code tags added.

@zfbot
Owner

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

@[~krishna@dioxe.com]
Is this a question or a bug report?
For questions please use the [mailing lists|http://framework.zend.com/wiki/display/ZFDEV/Mailing+Lists].

@zfbot
Owner

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

I hope its a bug

@zfbot
Owner

This issue was ported from the ZF2 Jira Issue Tracker at
http://framework.zend.com/issues/browse/ZF2-518

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

@netelix

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

@ThaDafinser

@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
Something went wrong with that request. Please try again.