gpt4 book ai didi

collections - 如何在 ZF2 中的表单集合上使用 setAttribute?

转载 作者:行者123 更新时间:2023-12-04 05:10:11 25 4
gpt4 key购买 nike

我还没有找到任何用于为 Zend Framework 2 表单集合设置字段属性的文档。我可以像这样设置单个输入字段的值:
$form->get('title')->setAttribute('value', $value);
我想不通的是如何设置集合的值。
$form->get('sample_collection')返回 Zend\Form\Element\Collection 对象

似乎我需要更深入一层并选择特定字段,以便我可以使用 ->setAttribute就可以了。

预先感谢您帮助解决此问题。

最佳答案

使用表单集合作为数组:

$elements = $form->get('sample_collection');
foreach($elements as $element){
$element->setAttribute('value', $value);
}

关于collections - 如何在 ZF2 中的表单集合上使用 setAttribute?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14985653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com