【发布时间】:2016-05-13 00:00:01
【问题描述】:
我在树枝模板中创建了一个表格。在第一列中,您可以选中一个复选框。检查复选框后,它应该删除该行。我的问题是如何让数据删除它。
这是我的桌子
<table class="table table-bordered table-striped table-hover">
<thead>
<tr>
<th> <label for="checbox">Check</label></th>
<th>id</th>
<th>Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
{% for products in user.products %}
<tr>
<td><input type="checkbox" name="checkBox" id="ic" value=true/></td>
<td >{{ products.id }}</a></td>
<td >{{ products.name }}</td>
</tr>
{% endfor %}
</tbody>
</table>
if(isset($_POST['checkBox'])== 'true'){
$products = $_POST['??????'];
$zl = 0;
foreach ($products as $pr)
{
$em = $this->getDoctrine ()->getManager ();
$pr = $em->getRepository('UserBundle:Products')->find($pr);
$user->removeProduct($pr);
++$zl;
}
$em->persist($user);
$em->flush();
}
如何获取数据? $products = $_POST['??????'];我不知道我必须在此处放置哪个参数才能从选定的复选框中获取数据。
【问题讨论】:
-
我建议您在 Ajax 中执行此操作。尝试将您的 PHP 代码放入您通过 Javascript 使用 Ajax 调用的文件中。
标签: php mysql symfony checkbox twig