Question

I have a view helper that returns an array called $this->getTypes();

I've set it up as an invokable:

'view_helpers' => array(
    'invokables' => array(
        'getTypes' => 'Account\View\Helper\GetTypes',
    ),
),

If I echo it in the view can see the array, but in the form it fails.

I would like something like:

$this->add(array(
    'name'       => 'type_id',
    'type'       => 'Zend\Form\Element\Select',
    'attributes' => array(
        'required' => 'required',
    ),
    'options'    => array(
        'label'            => 'Type *',
        'value_options'    => $this->getTypes(),
    ),
));

Any ideas?

Was it helpful?

Solution

The short answer is: you don't

The medium answer is: to get DB-Values into your Zend\Form\Element\Select you have to inject your DB-/Service-Layer into your Form.

The long answer is: written in my Blog post Zend\Form\Element\Select and Database Values

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top