I have a problem with form element select in ZF2. I create query doctrine 2 and have good results objects list.
$langs = $this->getEntityManager()->getRepository('Application\Entity\Langs')->findAll();
And create simple form:
class Coupon extends Form
{
protected $objectManager;
public function __construct($name = null)
{
parent::__construct('coupon');
$this->setAttribute('method', 'post');
$this
->setAttribute('method', 'post')
->setHydrator(new ClassMethodsHydrator(false))
;
$this->add(array(
'name' => 'id',
'attributes' => array(
'type' => 'hidden',
),
));
}
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'name' => 'language',
'attributes' => array(
'class' => 'form-control',
),
'options' => array(
'label' => 'default.form.message',
'empty_option' => '--- choose formElementName ---',
'value_options' => array(
'0' => 'French',
'1' => 'English',
'2' => 'Japanese',
'3' => 'Chinese',
),
)
));
}
How can convert result ($langs) to array for value_options - zend element select? What should I use for this?
I resolve it.
I create
and add init in form:
It works :) Thx Sam.