ZendFramework - How to create optgroup and there option using view helpers?

后端 未结 2 1284
臣服心动
臣服心动 2021-02-05 19:42

How do i create this with $this->formSelect() ?


                        
    
提交评论

  • 2021-02-05 20:10

    In Zend Framework 2 this can be done as follows:

    $this->add(array(
            'name'=>'Test',
            'type'=>'Zend\Form\Element\Select',
            'attributes'=>array('type'=>'select','required'=>'required'),
            'options'=>array(
                'label'=>'Test',
                'value_options'=>array('fruits'=>array('label'=>'Fruits','options'=>array('1'=>'Apple','2'=>'Mango')),'animals'=>array('label'=>'Animals','options'=>array('cat'=>'CAT','dog'=>'DOG'))),
                'empty_option'=>'Please Select'
            ),
    
        ));
    

    please note that an option named empty_options doesn't exist instead empty_option should be used.

    0 讨论(0)
  • 提交回复
    热议问题