本文主要是介绍tp5-分页与批量删除,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<!DOCTYPE html>
<html><head><meta charset="utf-8"><title>教室管理</title><!-- Bootstrap core CSS --><link href="http://localhost/attence/public/static/admin/css/bootstrap.css" rel="stylesheet"><link href="http://localhost/attence/public/static/admin/css/admin.css" rel="stylesheet"><link rel="stylesheet" href="http://localhost/attence/public/static/admin/font-awesome/css/font-awesome.min.css"><!-- Page Specific CSS --><link rel="stylesheet" href="http://localhost/attence/public/static/admin/css/morris-0.4.3.min.css"><link rel="stylesheet" href="http://localhost/attence/public/static/admin/css/custom.css"> <style type="text/css">.col-lg-4{width: 100%;}th,td{text-align: center;}</style> <script src="http://localhost/attence/public/static/admin/js/jquery-1.10.2.js"></script><script src="http://localhost/attence/public/static/admin/js/bootstrap.js"></script><script>function deleteClassroom(){ var checkedNum = $("input[name='tag']:checked").length; if(checkedNum==0){ alert("请至少选择一项!"); return false; } if(confirm("确定删除所选项目吗?")){ var checkedList = new Array(); $("input[name='tag']:checked").each(function(){ checkedList.push($(this).val()); }); var delitems = checkedList.toString(); window.location.href="{:url('deletemore')}?data="+delitems ;}}function qx(){ //全选$(":checkbox").prop("checked",true );}function reves(){ //反选$.each($(":checkbox"),function(){$(this).prop("checked",!$(this).prop("checked"));});}</script> </head><body>{include file="common:header" /}{include file="common:menu" /}<div id="wrapper"> <div id="page-wrapper" style="padding-top: 60px"><div class="row"> <div class="col-lg-12"><ol class="breadcrumb"><li class="active"><a href="{:url('user/index')}"><i class="fa fa-dashboard"></i> 首页</a></li><li class="active">教室管理</li></ol></div></div><div class="row"><div class="panel panel-info" style="margin-left: 10px"><div class="panel-heading"><h3 class="panel-title">教室列表</h3></div><div class="panel-body"><div class="form-group input-group"><button type="button" class="btn btn-success" float: left; onclick="javascript:window.location.href='{:url('addclassroom')}'">添加教室</button><button type="button" class="btn btn-danger" float: left; onclick="deleteClassroom()">批量删除</button> <form action="{:url('queryclassroom')}" method="post" style="margin-left:600px;margin-top: -35px;"><input type="text" class="form-control" name="roomname" style="width: 300px;" placeholder="请输入教室位置查询"> <span class="input-group-btn" style="display: inline-block;margin-left: -5px"><button class="btn btn-default" type="submit" ><i class="fa fa-search"></i></button></span> </form> </div> <div class="table-responsive"><table class="table table-bordered table-hover table-striped tablesorter"><thead><tr><th><input type="checkbox"></th><th>位置 </th><th>操作 </th></tr></thead><tbody>{volist name="res" id="vo"}<tr><td><input type="checkbox" name="tag" value="{$vo.id}"></td><td>{$vo.roomname}</td><td> <button type="button" class="btn btn-primary" style="height: 30px;width: 50px;padding: 5px" onclick="javascript:window.location.href='{:url('editclassroom',array('id'=>$vo['id']))}'">编辑</button> <button type="button" class="btn btn-danger" style="height: 30px;width: 50px;padding: 5px" onclick="javascript:if(confirm('确定删除id为'+{$vo.roomname}+'的教室吗?')){window.location.href='{:url('deleteclassroom',array('id'=>$vo['id']))}}'}">删除</button></td></tr>{/volist}</tbody></table><div><div class="form-group"><a class="btn btn-default" onclick="qx()" >全选</a><a class="btn btn-default" onclick="reves()">反选</a> </div><div class="bs-example" style="margin-left:400px;margin-top: -70px">{$res->render()} </div> </div></div> </div></div></div></div></div></body> </html>
controller
<?php
namespace app\admin\controller;
use app\admin\model\Classroom as ClassroomModel;class Classroom extends Common
{public function classroomlist(){$classroom = new ClassroomModel();$res = $classroom->queryrooms();$this::assign('res',$res);return view();}public function queryclassroom(){if (request()->isPost()) {$data = input("post.");$roomname = $data['roomname'];$res = db('classroom')->where('roomname',$roomname)->paginate(6);} $this->assign('res',$res);return view("classroomlist");}public function addclassroom(){if (request()->isPost()) {$classroom = new ClassroomModel();$res = $classroom->addclassroom(input("post."));if ($res) {$this->success("添加成功~",url('classroomlist'));}else{$this->error("添加失败!");}return;}return view();}public function editclassroom($id){if (request()->isPost()) {$classroom = new ClassroomModel();$res = $classroom->editclassroom(input("post."));if ($res == 2) {$this->error("教室位置不能为空");}if ($res) {$this->success("修改成功~",url('classroomlist'));}else{$this->error("修改失败!");}return;}$classrooms = db('classroom')->find($id);if (!$classrooms) {$this->error("该教室不存在!请检查~");}$this->assign("res",$classrooms);return view();}public function deleteclassroom($id){$classroom = new ClassroomModel();$res = $classroom->deleteclassroom($id);if ($res) {$this->success("删除成功~",url('classroomlist'));}else{$this->error("删除失败!");}return; }public function deletemore(){$data = input("get.data");$num = db('classroom')->delete($data);if ($num) {$this->success("删除成功!",url('classroomlist'));}return;}}
model
<?php
namespace app\admin\model;
use think\Model;
use think\Db;class Classroom extends Model
{public function queryrooms(){return $this::paginate(6);}public function addclassroom($data){if (empty($data) || !is_array($data)) {return false;}if ($this->save($data)) {return true;}else{return false;}}public function editclassroom($data){if (empty($data['roomname'])) {return 2;}if ($this->update($data)) {return 1;}else{return 0;} }public function deleteclassroom($id){if ($this::destroy($id)) {return true;}else{return false;}}
}
图片:
这篇关于tp5-分页与批量删除的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!