0
其實我無法理解,zend framework 2如何爲表單元素生成HTML。例如,如何在Zend framework-2表單中自定義複選框組?
$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,怎麼能我這麼做?
這可能會幫助你http://stackoverflow.com/questions/13931834/ zend-framework-2-form-element-decorators – Orangepill
我已經檢查過,但仍然沒有得到checkbox組的解決方案。我可以自定義一些,但不能使用複選框組。當我寫echo $ this-> formElement($ elements ['others']);它總是生成這些代碼組。 –
也許這個'$ others-> setAttribute('name','others') - > setLabel('Others');' – Amir