-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Hotfix/multiple nested collection test #5495
Hotfix/multiple nested collection test #5495
Conversation
public function testCanBindObjectMultipleNestedFieldsets() | ||
{ | ||
|
||
$productFieldset = new \ZendTest\Form\TestAsset\ProductFieldset(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please import the classes using use
statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've copied it from the function above. The class is full of that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Maks3w There it is!
$shop[1] = new stdClass(); | ||
$shop[1]->products = $products; | ||
|
||
$market->collection = $shop; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do no see any element named "collection" in the form
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right!
), | ||
)); | ||
|
||
$mainFieldset = new Fieldset('main'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And once again, $mainFieldset should be Collection according to the object. You've mixed up with fieldsets and binding object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Form has a mainFieldset, that has a collection of nestedFieldset, that has a collection of productFieldset. the missing part is useasbasefieldset.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be something like this
$form = new Form();
$form->setHydrator(new ObjectPropertyHydrator());
$form->add(array(
'name' => 'main',
'type' => 'Collection',
'options' => array(
'target_element' => $nestedFieldset,
'count' => 2
),
));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assume this:
Fieldset = object
Collection = array/Traversable
Element = object property/class method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$market -> $form
$shop -> "main" fieldset but should be a collection
????? -> "nested" collection
.....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to achieve two levels of collections.
Form
--> Fieldset
--> --> Collection
--> --> --> Fieldset
--> --> --> --> Collection
--> --> --> --> --> Fieldset
I think i understand your issue. So you should do something like these $nestedFieldset = new Fieldset('nested');
$nestedFieldset = new Fieldset('nested');
$nestedFieldset->setHydrator(new ClassMethods());
$nestedFieldset->setObject(new Stdclass()); // or what ever you object is
....
....
....
$mainFieldset = new Fieldset('main');
$mainFieldset->setHydrator(new ClassMethods());
$mainFieldset->setObject(new Stdclass()); // or what ever you object is Otherwise nested objects would not bound to appropriate fieldsets |
I'm not doing it in the test, but i am doing in my actual code. If you could test it, it would be really awesome. I know its a bit too much to ask, but i'm on that issue for more than one week and i really need it working to move ahead. I'ts a really simplified use case with only the necessary things. Nested objects should be bound to the appropriate fieldsets, if its not doing it right now, it should be fixed, and i've been working hard to fix that, with no success. |
@fabiocarneiro Have you been able to investigate this any further? Perhaps ping Bakura in #zftalk.dev on Freenode IRC to see if he can assist. |
- Unit test passes now, meaning we can close both issues.
Tests for making sure we can bind objects to multiple fieldsets and collections