How to populate Select element in ZF 2?

How to populate a select element in ZF 2 ? My entity object has correct value. When i bind object with form, form doesn't populate the select element with actual value.

Can't i do with just $oForm->bind($oMyEntityObject);

Note :: I am not talking about Select element's 'value_options' . I have tried to manually call setAttribute() method and set 'value' property. I just want to know is there anything i can do with bind() method ( $oForm->bind() )


bind() will use the form hydrator that is attached to the form to set the value, so it will depend on which type you use. The class methods hydrator would for instance, would call $oMyEntityObject's public methods that match the form element names.

It is therefore important that the select element foo has a corresponding class property foo and the class has a publicly accessible $oMyEntityObject->getFoo().

Select elements will also have the additional requirement of the value needing to be already within the value_options (So if $oMyEntityObject->getFoo() == 1 then your would require 'value_options' => array(1 => 'Foo option 1') for it to be correctly set using bind($oMyEntityObject)).

Need Your Help

Is Dependency Injection possible with a WPF application?

wpf design-patterns dependency-injection inversion-of-control autofac

I want to start using dependency injection in my WPF application, largely for better unit testability. My app is mostly constructed along the M-V-VM pattern.

How to retrieve name of Javascript events attached to form in CRM 2016 server side

javascript c# dynamics-crm dom-events dynamics-crm-2016

I am trying to retrieve All the Javascript events/libraries attached to the form of particular entity from the server side.