I have a table which contains information for example "ID", "Category", "Name" and "Action". Now I want to improve the table with checkboxes which enables the user to choose multiple rows and to delete them in one step.
My problem: I have created a form with the form-builder:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('id', 'entity', array(
'required' => false,
'class' => 'AppBundle:Task',
'property' => 'id',
'multiple' => true,
'expanded' => true
))
->add('add', 'submit', array('label' => 'Add'));
}
This form is send to the twig-html with the table which contains the data for the table.
{% if table|length > 0 %}
{{ form_start(addForm) }}
{{ form_errors(addForm) }}
<table class='result' border=1>
<th></th>
<th>ID</th>
<th>Category</th>
<th>Name</th>
<th>Action</th>
{% for item in table %}
<tr>
<td>
{% for entity in addForm.id %}
{% if entity.vars.value == item.id %}
{{ form_widget(entity.vars.form) }}
{% endif %}
{% endfor %}
</td>
<td>{{ item.id }}</td>
<td>{{ item.category }}</td>
<td>{{ item.name }}</td>
<td>{{ item.action }}</td>
</tr>
{% endfor %}
</table>
As you can see my solution has to search in a for loop for the correct ID of the form-item and place them.
My problem now: I do not feel comfortable with this solution - is there a more easier way to display a table containing several columns and checkboxes?
Thanks in advance
EDIT:
Also have the problem that I get the following error after selecting some checkboxes:
Neither the property "id" nor one of the methods "addId()"/"removeId()", "setId()", "id()", "__set()" or "__call()" exist and have public access in class "AppBundle\Entity\XXXXXX".