Zend framework 2 loop through elements of element collection

夙愿已清 提交于 2019-12-12 02:20:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!