【问题标题】:Zend framework 2 loop through elements of element collectionZend framework 2 循环遍历元素集合的元素
【发布时间】:2023-03-09 03:32:02
【问题描述】:

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

 $this->add([
        'type' => 'Zend\Form\Element\Collection',
        'name' => 'some-name',
        'options' => [
            'label' => 'some name',
            'count' => 3,
            'target_element' => [
                'type' => 'text',
            ],
        ],
    ]);

如果我使用,此代码会呈现 3 个带有标签和字段集的输入

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

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

我想将集合的每个输入包装到 div 中。我的想法是遍历这个输入集合以提取输入。

我该怎么做?

【问题讨论】:

    标签: view zend-framework2 renderer


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2022-11-20
      • 1970-01-01
      • 1970-01-01
      • 2012-11-23
      • 2016-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多