作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我还没有找到任何用于为 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/
我是一名优秀的程序员,十分优秀!