【发布时间】:2013-05-29 05:08:52
【问题描述】:
其实我不明白,zend framework 2 如何为表单元素生成 HTML。例如,
$others = new Element\MultiCheckbox('others');
$others->setLabel('Others')
->setAttribute('name', 'others');
$others->setValueOptions(array(
'1' => 'Contacts',
'2' => 'Who viewd my profile'
));
此代码生成 -
<label><input type="checkbox" value="1" name="others[]">Contacts</label>
<label><input type="checkbox" value="2" name="others[]">Who viewd my profile</label>
但我需要按如下方式制作 HTML -
<input type="checkbox" value="1" name="others[]"><label>Contacts</label>
<input type="checkbox" value="2" name="others[]"><label>Who viewd my profile</label>
那么如果我想更改生成的 HTML,我该怎么做呢?
【问题讨论】:
-
我已经检查过了,但仍然没有得到复选框组的解决方案。我可以自定义一些,但不能使用复选框组。当我写 echo $this->formElement($elements['others']);它总是生成那组代码。
-
也许这个
$others->setAttribute('name', 'others') ->setLabel('Others'); -
@Amir :不,不是, setlabel('Others') 将为整个复选框组设置标签,默认情况下,每个标签内生成复选框组的每个复选框。这就是问题所在。
-
其实你提到的两种格式的结果都是一样的。对你来说有什么不同,真的吗?
标签: php html zend-framework zend-framework2 zend-form