test.html:
function del(id) {
if(confirm("确定删除?")){
$.ajax({
url:"/app/controller/Del.php/" +id,
success:function () {
alert("删除成功");
},
error:function () {
}
}
);
}
}
Del.php:
public function del(){
$id_arr = isset($_GET['id']);
$result = Db::table('user')->where('id',$id_arr)->delete();
//print_r($id_arr);
if($result){
echo json_encode(array("code"=>200));
}else{
echo json_encode(array('code'=>400));
}
}
这是目录结构
index.php:
public function test(){
$All = Db::table('user')->select()->toArray();
$id = array_column($All,'id');
$name = array_column($All,'name');
$pwd = array_column($All,'pwd');
/*Db::table('user')->where('id',3)->delete();*/
/* $id_arr = isset($_GET['id']) ;
Db::table('user')->where('id',$id_arr)->delete();
print_r($id_arr);*/
test.html:
<table class="layui-table" id="demo" lay-filter="demo">
<colgroup>
<col width="150">
<col width="200">
<col>
</colgroup>
<thead>
<tr>
<th id="id" width="100px">ID<i class="layui-icon layui-icon-cols" style="font-size: 30px; color: #1E9FFF;"></i></th>
<th width="400px">姓名<i class="layui-icon layui-icon-username" style="font-size: 30px; color: #1E9FFF;"></i> </th>
<th width="400px">密码<i class="layui-icon layui-icon-password" style="font-size: 30px; color: #1E9FFF;"></i></th>
<th width="400px">操作</th>
</tr>
</thead>
<tbody>
<tr>
{foreach $All as $key=>$nv}
<tr>
<th>
{$nv.id}
</th>
<th>
{$nv.name}
</th>
<th>
{$nv.pwd}
</th>
<th>
<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail" data-type="getCheckData" onclick="show()" >查看</a>
<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" onclick="del()">删除</a>
<!--<a href="{:url('index/test',['id'=>$nv.id])}">删除</a>-->
</th>
</tr>
{/foreach}
</tr>
</tbody>
</table>
View::assign('All',$All);
View::assign('arrayid',$id);
View::assign('arrayname',$name);
View::assign('arraypwd',$pwd);
return View::fetch();
}