Search code examples
phpmodel-view-controllerzend-frameworkmodulezend-framework2

zend framework 2 module: call function to populate a dropdownlist in the frontend


Hi im busy creating a module.

Now my problem is, i really want to understand how i would approach this problem.

1.I got a front-end that needs a dropdownlist that must be populated with data from a service function call to an api.

MyService.php

    public function myFunction() {
      return $call->get(/list/);
    }

Now how would i get the data as easy as possible to be used by others in the front-end when writing this Zend Framework 2 Module?

I would be happy to learn and be shown the right way.


Solution

  • I would recommend using: https://framework.zend.com/manual/2.4/en/modules/zend.form.view.helpers.html#formselect

    $element = new Element\Select('language');
    $element->setValueOptions(array(
        '0' => 'French',
        '1' => 'English',
        '2' => 'Japanese',
        '3' => 'Chinese'
    ));
    echo $this->formSelect($element);`
    

    this will generate a valid html selectbox, with the given options