Over a million developers have joined DZone.

Zend Framework 2: Select Optgroups

DZone's Guide to

Zend Framework 2: Select Optgroups

· Web Dev Zone
Free Resource

Start coding today to experience the powerful engine that drives data application’s development, brought to you in partnership with Qlik.

On my project I’m currently working on I needed to use optgroups. After looking high and low through the documentation and the code I discovered the feature kind of worked, but kind of didn’t. I issued a pull request that fixed the code for the next release (2.0.1) but here’s the skinny on how to set it up.

When setting the valueOptions attribute of a SelectElement specify an array as follows for optgroup support.

    return array(
            array('label' => 'Jazz', 'options' =>
            array('label' => 'Rock', 'options' =>
                'Alternative Rock',
                'Folk Rock',
                'Garage Rock',
                'Hard Rock',
                'Heavy Metal'


Create data driven applications in Qlik’s free and easy to use coding environment, brought to you in partnership with Qlik.


Published at DZone with permission of James Carr, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}