问题
I created a collection of inputs with Zend\Form\Element\Collection, like
$this->add([
'type' => 'Zend\Form\Element\Collection',
'name' => 'some-name',
'options' => [
'label' => 'some name',
'count' => 3,
'target_element' => [
'type' => 'text',
],
],
]);
This codes renders 3 inputs with label and fieldset if I use
echo $this->formCollection($form->get('some-name'));
(or the like of formCollection) in the view script.
I want to wrap each input of the collection into divs. My idea is to iterate over this input collection to extract the inputs.
How can I do this?
回答1:
You can treat the collection as a traversable object.
<?php foreach ($form->get('some-name') as $element) : ?>
<div>..</div>
<?php endforeach; ?>
来源:https://stackoverflow.com/questions/31588206/zend-framework-2-loop-through-elements-of-element-collection