How to add attributes (id for example) to options

2019-06-10 09:16发布

问题:

I need to add custom attributes (id, class) to options of Zend_Form_Element_Select.

How can I do that?

回答1:

You can pass in an "attribs" array when instantiating the element. For example:

    $form->addElement('select', 'type', array(
        'label' => 'Label',
        'multioptions' => $some_array,
        'attribs' => array('class' => 'selector', 'id' => 'whatever')
    ));


回答2:

AFAIK it's not possible to add ids to select's options. Option would be implementing your own viewHelper and adding this functionality. But generally it's not possible.