如何将zend表单元素添加到php中的表单中?
我的 zend 表单中有一个 foreach 循环,在本例中,$this->args[1]
的计数为 5:
foreach ($this->args[1] as $val)
{
$submitImage = new Zend_Form_Element_Image('submit_image');
$checkBox = new Zend_Form_Element_Checkbox('id_checkbox');
$this->addElement( $submitImage ->setImage($val->full_path) );
$this->addElement( $checkBox ->setValue($val->id) );
}
我遇到的问题是 $submitImage 和
$checkBox
被覆盖,我只得到每个元素的一个元素,即最后一个元素。
有什么想法如何让它们全部出现吗?
谢谢
我也尝试过:
$i=0;
foreach ($this->args[1] as $val)
{
$submitImage = 'submitImage'.$i;
$checkBox = 'checkBox'.$i;
$submitImage = new Zend_Form_Element_Image('submit_image');
$checkBox = new Zend_Form_Element_Checkbox('id_checkbox');
$this->addElement( $submitImage ->setImage($val->full_path) );
$this->addElement( $checkBox ->setValue($val->id) );
$i++;
}
但它不起作用
i have a foreach loop in my zend form, in this case the $this->args[1]
has a count of 5 :
foreach ($this->args[1] as $val)
{
$submitImage = new Zend_Form_Element_Image('submit_image');
$checkBox = new Zend_Form_Element_Checkbox('id_checkbox');
$this->addElement( $submitImage ->setImage($val->full_path) );
$this->addElement( $checkBox ->setValue($val->id) );
}
the problem i encounter is that the $submitImage
and $checkBox
get overwritten and i only get one element of each, the last one.
any ideas how to make them all show up?
thanks
i've also tried:
$i=0;
foreach ($this->args[1] as $val)
{
$submitImage = 'submitImage'.$i;
$checkBox = 'checkBox'.$i;
$submitImage = new Zend_Form_Element_Image('submit_image');
$checkBox = new Zend_Form_Element_Checkbox('id_checkbox');
$this->addElement( $submitImage ->setImage($val->full_path) );
$this->addElement( $checkBox ->setValue($val->id) );
$i++;
}
but it doesn't work
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你真的很接近,只需要一些小的修复。任何使元素名称独一无二的东西。
或者如果你喜欢
Liyali 有权利,我只是更冗长:)
[编辑]
更正了第二个循环中的变量冲突。
your really close, only need minor fixes. Anything to make the name of the element unique.
or if you like
Liyali has the right of it I'm just more verbose :)
[EDIT]
corrected variable collision in second loop.
您的元素名称必须不同。
Your element names must be different.