возможно, кто-то может мне помочь, потому что я с неделю копаю форумы и документацию, как сделать таблицу, где у меня есть форма в 3-м столбце.
У меня есть класс CollectionController со следующим фрагментом:
return $this->render(
'vollmachtapp/pages/collections/list2.html.twig',
[
'attachmentForm' => $attachmentForm->createView(),
'list' => $apiClient->listAllVollmachten()
]
);
AttachForm выглядит следующим образом:
$attachmentForm = $this->createForm( SimpleAttachmentType::class, $attachment );
Вот мой SimpleAttachmentType:
class SimpleAttachmentType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('file', FileType::class)
->add('vollmachtId', HiddenType::class)
->add('save', SubmitType::class, ['label' => 'Vollmacht hochladen']);
}
}
Теперь я использую веточку, которая выглядит так:
<table id="datatable" class="table table-striped table-bordered">
<thead>
<tr>
<th>Vollmacht ID</th>
<th>Users</th>
<th>Upload/Download</th>
</tr>
</thead>
<tbody>
{% for collection in list.items %}
<tr>
<td>{{ collection.id }}</td>
<td>
{% for user in collection.users %}
<a href="{{ url('user_detail', {'id': user.id}) }}">
{{ user.name }}
</a><br>
{% endfor %}
</td>
<td>
<a href="{{ url('downloadVollmacht', {'id': user.id}) }}"><button type="button" class="btn btn-sm btn-primary">Download Vollmacht</button></a>
{% if(app.user.role == "admin") %}
<hr>
<div class="text-center mtop20">
{{ form_start(attachmentForm, {method: 'POST'}) }}
{% if not attachmentForm.vars.valid %}
<div class="alert alert-danger alert-dismissible fade in" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
{{ form_errors(attachmentForm.file) }}
</div>
{% endif %}
{{ form_widget(attachmentForm.vollmachtId, {'name': vollmachtId, 'value': collection.id}) }}
{{ form_widget(attachmentForm.file) }}
<br />
{{ form_widget(attachmentForm.save, {attr: {'class': 'btn-left btn btn-sm btn-primary'}}) }}
{{ form_end(attachmentForm) }}
</div>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
У меня проблема, форма отображается только в 1-й строке таблицы. Кто-нибудь может сказать мне, что я делаю не так, и нужно изменить, чтобы это заработало?
Спасибо и всего наилучшего,
Майкл Обстер