Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Zend Framework 2中将元素从循环添加到Zend表单_Php_Zend Framework2 - Fatal编程技术网

Php 在Zend Framework 2中将元素从循环添加到Zend表单

Php 在Zend Framework 2中将元素从循环添加到Zend表单,php,zend-framework2,Php,Zend Framework2,向Zend 2窗体添加元素时 foreach($headers as $column) { $checkbox = new Element\Checkbox('checkbox'); $checkbox->setLabel($column . ""); $checkbox->setUseHiddenElement(true); $

向Zend 2窗体添加元素时

  foreach($headers as $column)
            {
                $checkbox = new Element\Checkbox('checkbox');
                $checkbox->setLabel($column . "");
                $checkbox->setUseHiddenElement(true);
                $checkbox->setCheckedValue("true");
                $form->add($checkbox);
            }

我遇到了只添加最后一个元素的问题。通过逐步查看代码,我知道它多次运行循环,但是Zend表单的
add()
代码似乎只是映射最后一个元素,而不是添加所有元素。做这样的事情最好的方法是什么

您需要为每个元素指定一个唯一的名称,而不仅仅是“复选框”

试试这个:

$checkbox = new Element\Checkbox($column);