我有一张表格,其中包含保存在数据库中的所有comissões。在此表中,用户可以删除任何行:
删除操作是视图上的postLink:
<?php
echo $this->Form->postLink(
__('<i class="glyphicon glyphicon-trash"></i>'),
array(
'action' => 'delete', $contratos[0]['Contrato']['id'],
$comissao['ContratoComissionario']['id']
),
array(
'class' => 'btn btn-danger btn-xs',
'escape' => false,
'data-toggle'=>'tooltip',
'title' => 'delete'
),
__('Você tem certeza de que deseja deletar essa comissão?')
);
&GT;
这是控制器:
public function delete($idContrato = null, $id = null) {
if (!$this->request->is('post')) {
throw new MethodNotAllowedException();
}
$this->ContratoComissionario->id = $id;
if (!$this->ContratoComissionario->exists()) {
throw new NotFoundException(__('Comissão inválida'));
}
if ($this->ContratoComissionario->delete()) {
$this->Session->setFlash(__('Comissão deletada com sucesso'), 'flash/success');
$this->redirect(array('action' => 'add', $idContrato));
}
$this->Session->setFlash(__('Comissão não pôde ser deletada'), 'flash/error');
$this->redirect(array('action' => 'index', $idContrato));
}
删除操作就像表格中所有行的魅力一样,但第一个。当我点击第一个删除图标时,显示确认消息,没有其他任何事情发生。
我发现没有创建第一行的表单。这是为第二个图标生成的HTML:
<td>
<form action="/ModuloContratos/ContratoComissionarios/delete/3/11" name="post_55fc1552e0890053880032" id="post_55fc1552e0890053880032" style="display:none;" method="post"><input type="hidden" name="_method" value="POST">
</form>
<a href="#" class="btn btn-danger btn-xs" data-toggle="tooltip" title="" onclick="if (confirm("Voc\u00ea tem certeza de que deseja deletar essa comiss\u00e3o?")) { document.post_55fc1552e0890053880032.submit(); } event.returnValue = false; return false;" data-original-title="delete">
<i class="glyphicon glyphicon-trash"></i>
</a>
</td>
这是为第一个图标生成的HTML:
<td>
<input type="hidden" name="_method" value="POST">
<a href="#" class="btn btn-danger btn-xs" data-toggle="tooltip" title="" onclick="if (confirm("Voc\u00ea tem certeza de que deseja deletar essa comiss\u00e3o?")) { document.post_55fc1552e0113745519359.submit(); } event.returnValue = false; return false;" data-original-title="delete">
<i class="glyphicon glyphicon-trash"></i>
</a>
</td>
如何强制postLink为所有行创建表单?我正在使用CakePHP 2.7.2。