我想渲染:
<input type="text" value="" name="foo[]" />
<input type="text" value="" name="bar[]" />
但是Zend_Form_Element需要一个(字符串)名称,所以我需要这样做:
$this->addElement('text', '1', array(
'belongsTo' => 'foo'
));
$this->addElement('text', '2', array(
'belongsTo' => 'bar'
));
但是输出是:
<input id="foo-1" type="text" value="" name="foo[1]" />
<input id="bar-2" type="text" value="" name="bar[2]" />
我也可以接受类似的输出:
<input id="foo-1" type="text" value="" name="foo[1]" />
<input id="bar-1" type="text" value="" name="bar[1]" />
但是Zend_Form_Element重写具有相同名称的元素
有什么方法可以做我需要的吗?
最佳答案
对于多个值:
$foo = new Zend_Form_Element_Text('foo');
// Other parameters
$foo->setIsArray(TRUE);
$this->addElement($foo);
生成:
name="foo[]"
--
如果您要查找给定的 key (例如
name="foo[bar]"
),请使用:$bar= new Zend_Form_Element_Text('bar');
// Other parameters
$bar->setBelongsTo('foo');
$this->addElement($bar);
--
在ZF 1.11.5上测试
关于zend-form - Zend_Form数组符号和空元素名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1638706/