【发布时间】:2018-06-01 15:23:43
【问题描述】:
我正在尝试在模式中使用编辑表单,但此编辑表单在上下文中不起作用。
当我使用 URI 地址在网页中直接尝试表单时它可以工作,但当我在我的页面上下文中尝试它时却不行。我会解释更多...
在我的网页中,我有一个render controller:
<div class="card">
<div class="body">
{{ render(controller('AppBundle:Classeur3:vacation', {'request':app.request , 'id': zone.id})) }}
</div>
</div>
这个控制器检索一些实体并显示如下表格:
<table id="sites-list" class="table table-bordered datatable">
<thead>
<tr>
<th>Employé</th>
<th>Heure d'entrée</th>
<th>Heure de sortie</th>
<th>Durée</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for v in vacations %}
<tr id="tr-vacation-{{ v.id }}">
<td>{{ v.user }}</td>
<td>{{ v.entryTime|date }}</td>
<td>{{ v.exitTime|date }}</td>
<td>{{ v.totalTime }}</td>
<td style="width: 150px;">
<button onclick="$('#modal').modal({remote: '{{ path('edit_vacation', {'id': v.id}) }}' });" type="button" class="btn btn-circle waves-effect waves-circle waves-float" style="margin-right: 5px;">
<i class="material-icons">search</i>
</button>
</td>
</tr>
{% endfor %}
</tbody>
</table>
我的edit_vacation 资源是通过以下路线定义的:
edit_vacation:
path: /vacation/{id}/edit
defaults: { _controller: AppBundle:Classeur3:editVacation }
这是我的控制器功能:
public function editVacationAction(Request $request, $id){
$vacation = $this->getDoctrine()->getRepository(Answ31Vacation::class)->find($id);
$form = $this->createForm(Answ31VacationType::class, $vacation);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($vacation);
$entityManager->flush();
//Message
$this->addFlash('success', 'Vacation mise à jours');
//Redirect to Zone edit page
return $this->redirectToRoute('zone_edit', array('id' => $vacation->getZone()->getId()));
}
return $this->render('AppBundle:Classeur3:edit_vacation.html.twig', array(
"form" => $form->createView()
));
}
这是我的观点:
<div class="modal-body">
<div class="row">
<div class="col-sm-12">
{{ form(form) }}
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-link waves-effect" data-dismiss="modal">Fermer</button>
</div>
模态显示完美,但是当我提交表单时,页面按计划重新加载但数据没有更新。 当我尝试直接在 URL 中调用我的资源( baseurl/vacation/1/edit )时,我有表单并且修改正在工作,当我按下提交按钮时,数据会更新。
有什么想法吗?
【问题讨论】:
-
当您在没有其他表单的页面上打开模态框时是否有效?
-
您的渲染语句似乎指向了一个假期方法,而您的代码似乎显示了 editVacationAction?但更重要的是,在浏览器中查看 html 源代码并查看表单发布到的位置。
标签: forms symfony controller render