1

I have created custom plunging to get list of values from the database.

Now I want create a Drop-Down list using this array

This is my Select List

$this->add(array(
    'name' => 'group_name',
    'type' => 'select',
    'attributes' => array(
        'id'=>'group_name',
        'class'=>'large',
    ),
    'options' => array(
        'label' => 'Select List',
        'value_options' => array(
            '1' => 'php',
            '2' => 'java'
        ),
    ),
));
1
  • Even I am lazy to start from scratch :P Commented Oct 25, 2013 at 4:21

3 Answers 3

2

You do not give all too much information about what it actually is, that you have trouble with, but for now I will assume that you have trouble to get Database Values into your Select elements. For this, please see detailed information on my Blog:

The basic you need to understand is simple Depedency Injection. You will need to properly inject the Data-Sources (or the Data itself) into your Form. This is done using the ServiceManager of Zend Framework 2.

Since there are many different pathes one can choose (and even my Blog doesn't cover them all), i won't go into detail of any specific one until you request so. The Blog itself should be enough to get you started to be able to write a proper SO-Question ;)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Sam, This is exactly what i wanted.
0

What part of this is it you need help with? The HTML? The loop in PHP? HTML:

<form action="" method="get">
<select name="group_name">
  <option value="1">php</option>
  <option value="2">java</option>
</select>
</form>

The PHP, for the group_name:

echo $array['name'];

For the looping through the select values:

foreach($array['options']['value_options'] AS $key=>$option){
    echo '<option value="'.$key.'">'.$option.'</option>';
}

Something like this...???

Comments

0

Don't go for the hardest thing `In Controller, add

$urFormObject->get('selectOptionName')->setValueOptions($listArray);
Example: 

$formName->get('group_name')->setValueOptions($listArray);`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.