Just trying to get a select field populated from a database table. This is just a simple table with a primary key column and another column named type.
Just for testing, the example table consists of:
id type
1 Sample 1
2 Sample 2
3 Sample 3
When I create a form:
$builder
->add('account_type', EntityType::class, array(
'class' => 'AppBundle:AppAccountTypes',
'choice_label' => 'type'
));
My select dropdown simply repeats the first entry 3 times.
<select id="add_account_form_account_type" name="add_account_form[account_type]" class="form-control">
<option value="1">Sample 1</option>
<option value="1">Sample 1</option>
<option value="1">Sample 1</option>
</select>
For testing sake, the controller is just using:
$account = new Account();
$form = $this->createForm(new AddAccountForm(), $account);
return $this->render('account/new.html.twig', array(
'page_title' => 'Create Account',
'form' => $form->createView()
));
Twig template:
{% extends 'base.html.twig' %}
{% block body %}
<h1>{{ page_title }}</h1>
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}
{% endblock %}
What am I missing here?
AppAccountTypes.php
Entity file.