Ada*_*mon 5 zend-form zend-form-sub-form
我想渲染:
<input type="text" value="" name="foo[]" />
<input type="text" value="" name="bar[]" />
Run Code Online (Sandbox Code Playgroud)
但是Zend_Form_Element需要一个(字符串)名称,所以我需要这样做:
$this->addElement('text', '1', array(
'belongsTo' => 'foo'
));
$this->addElement('text', '2', array(
'belongsTo' => 'bar'
));
Run Code Online (Sandbox Code Playgroud)
但输出是:
<input id="foo-1" type="text" value="" name="foo[1]" />
<input id="bar-2" type="text" value="" name="bar[2]" />
Run Code Online (Sandbox Code Playgroud)
我也可以接受如下输出:
<input id="foo-1" type="text" value="" name="foo[1]" />
<input id="bar-1" type="text" value="" name="bar[1]" />
Run Code Online (Sandbox Code Playgroud)
但Zend_Form_Element重写了同名的元素
有办法做我需要的吗?
对于多个值:
$foo = new Zend_Form_Element_Text('foo');
// Other parameters
$foo->setIsArray(TRUE);
$this->addElement($foo);
Run Code Online (Sandbox Code Playgroud)
产生: name="foo[]"
-
如果您正在寻找给定的密钥name="foo[bar]",请使用:
$bar= new Zend_Form_Element_Text('bar');
// Other parameters
$bar->setBelongsTo('foo');
$this->addElement($bar);
Run Code Online (Sandbox Code Playgroud)
-
在ZF 1.11.5上测试
| 归档时间: |
|
| 查看次数: |
4293 次 |
| 最近记录: |