我想在Zend Framework 2表单中为select选项添加自定义HTML属性.
这是我的Form类中的(部分)代码:
$this->add(array(
'name' => 'lieuRemplissage',
'type' => 'Select',
'attributes' => array(
'class' => 'form-control',
),
'options' => array(
'label' => _('Lieu pré-enregistré'),
),
));
Run Code Online (Sandbox Code Playgroud)
我在我的控制器中填充我的选项值,如下所示:
$form = new \Vente\Form\Vente;
foreach($this->getAdminLieuDeVenteTable()->fetchAll() as $lieu) {
$optionsLieu[$lieu->getId()] = $lieu->getNom();
}
$form->get('lieuRemplissage')->setValueOptions($optionsLieu);
Run Code Online (Sandbox Code Playgroud)
但是现在,对于每个选项,我想为所有选择选项添加一个html属性,但每个选项的值都不同.
有没有办法在ZF2中实现这一目标?
谢谢.