Zend 框架 2 循环遍历元素集合的元素 [英] Zend framework 2 loop through elements of element collection

查看:37
本文介绍了Zend 框架 2 循环遍历元素集合的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Zend\Form\Element\Collection 创建了一个输入集合,比如

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',
            ],
        ],
    ]);

如果我使用

echo $this->formCollection($form->get('some-name'));

(或 formCollection 之类的)在视图脚本中.

(or the like of formCollection) in the view script.

我想将集合的每个输入都包装到 div 中.我的想法是迭代这个输入集合来提取输入.

I want to wrap each input of the collection into divs. My idea is to iterate over this input collection to extract the inputs.

我该怎么做?

推荐答案

您可以将集合视为可遍历的对象.

You can treat the collection as a traversable object.

<?php foreach ($form->get('some-name') as $element) : ?>
  <div>..</div>
<?php endforeach; ?>

这篇关于Zend 框架 2 循环遍历元素集合的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆