我想要在一個視圖中編輯所有對象的表單。在一個頁面中編輯所有實體對象的形式Symfony3
了,我有這樣的效果:
但是,當我嘗試編輯一個簡單的對象,這是行不通的。
Corrections.html.twig
<div class="row">
<div class="col-sm-10 col-sm-offset-1">
<table class="table table-bordered">
<thead>
<tr>
<th>Nazwa poprawki</th>
<th>Status dla</th>
<th>Status dla klienta</th>
<th>Nazwa projektu</th>
<th>Klient</th>
<th>Obszar</th>
<th>Piorytet</th>
<th>Data utworzenia</th>
<th>Iteracja</th>
</tr>
</thead>
<tbody>
{% for correction in corrections %}
{{ form_start(form[loop.index0]) }}
<tr>
<td>{{correction.correctionName}}</td>
<td>{{ form_widget(form[loop.index0].adminStatusCorrectionId) }}</td>
<td>{{ form_widget(form[loop.index0].userStatusCorrectionId) }}</td>
<td>{{correction.projectId.projectName}}</td>
<td>{{correction.projectId.userId.firstName}} {{correction.projectId.userId.lastName}}</td>
<td>{{ form_widget(form[loop.index0].areaId) }}</td>
{% if correction.priority %}
<td>Tak</td>
{% else %}
<td>Nie</td>
{% endif %}
<td>{{correction.creationDate|date('Y-m-d')}}</td>
<td>{{correction.iteration}}</td>
<td>{{ form_widget(form[loop.index0].save) }}</td>
</tr>
</form>
{{ form_end(form[loop.index0]) }}
{%endfor %}
</tbody>
</table>
</div>
</div>
AdministratorController.php
public function correctionsAction(Request $request) {
$repository = $this->getDoctrine()->getRepository('AppBundle:Correction');
$corrections = $repository->findAll();
foreach ($corrections as $key => $value) {
$form = $this->createForm(CorrectionType::class, $corrections[$key]);
$formView[] = $form->createView();
}
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$correction = $form->getData();
$em = $this->getDoctrine()->getManager();
$em->persist($correction);
$em->flush();
return $this->redirectToRoute('admin_view_corrections');
}
return $this->render('administrator/corrections.html.twig', array(
'corrections' => $corrections,
'form' => $formView
));
}
CorrectionType.php
class CorrectionType extends AbstractType {
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add('adminStatusCorrectionId', EntityType::class, array(
'class' => 'AppBundle:AdminStatusCorrection',
'choice_label' => 'statusName'
))
->add('userStatusCorrectionId', EntityType::class, array(
'class' => 'AppBundle:UserStatusCorrection',
'choice_label' => 'statusName'
))
->add('areaId', EntityType::class, array(
'class' => 'AppBundle:Area',
'choice_label' => 'areaName'
))
->add('save', SubmitType::class, array('label' => 'Aktualizacja'))
;
}
public function configureOptions(OptionsResolver $resolver) {
$resolver->setDefaults(array(
'data_class' => Correction::class,
));
}
}
我現在可以做什麼?
編輯
我的所有形式的有 「修正」 的名字。
在這種情況下,我已經得到了12點的形式:
<form name="correction" method="post"></form>
你能給我們提供你得到的錯誤嗎? –