我想通過一次單擊來刪除所選的多行或所有行。 但我不能確定它。我怎麼能用我的代碼做到這一點?請編輯我的代碼以獲得預期結果。在phalcon中刪除多個選定的行
這裏是我的選擇所有的行
[Jquery]
function selectAll(status){
$('input[name=slId]').each(function(){
$(this).prop('checked', status);
});
}
jQuery的如何獲得ID在給控制器執行刪除過程?我的jquery不發送任何id,我用var_dump測試它的顯示NULL。
[Controller]
public function deleteAction()
{
if($this->request->isPost())
{
if($this->session->has('uname'))
{
$id = array();
$id = $this->request->getPost('id');
$data = Blogs::findByid($id);
if(!$data->delete())
{
echo('Unable to Delete');
}
}
}
}
[volt]
{{ form('blog/delete', 'enctype': 'multipart/form-data') }}
<table class="bloglist">
<thead>
<tr class="fbold">
<td>
{{check_field('checkbox','id':'sall','onclick':'selectAll(this.checked)')}} </td>
<td>Title</td>
<td>Author</td>
<td>Views</td>
<td>PublishedOn</td>
</tr>
</thead>
<tbody>
{%for all in ball %}
<tr class="zebra">
<td>{{check_field('slId', 'class':'slId','id':all.id)}}</td>
<td class="tal">{{all.btitle}}</td>
<td>{{all.bauthor}}</td>
<td>{{all.views}}</td>
<td>{{all.datetime}}</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
<td colspan="6">{{submit_button('DELETE')}}</td>
</tr>
</tfoot>
</table>
{{end_form()}}
您的表單提交至'blog/delball',但您的刪除代碼位於您的'deleteAction()' – Timothy
更新我的答案。但真的它沒有得到ids和如何處理多個ids數組? – munaz
不確定你的控制器代碼,但在jquery中有語法錯誤,'$('input [name = slId]')'應該是'$('input [name =「slId」]')'注意雙引號對於名稱值 –