注意分页的方法有两种:一种是thinkphp3.2 自带的 另一种是之前新闻页用过的 显示效果稍有差别
显示效果:
细节问题:
①搜索页面 要加session判断 和 分页
②修改和添加页面需要有session判断
③增删改的权限设置
控制器端:
<?php
namespace Home\Controller;
use Think\Controller;
class UserController extends Controller
{
public function User(){ if (session('?username')) {
$m=M('fruit');
//$arr=$m->select();
//var_dump($arr);
$total=$m->count();
//$this->assign('data',$arr);
$this->assign('sess',session('username')); $page=new \Home\Publics\Page($total,3);
//$page->limit;//limit n,n
$sql="select * from fruit ".$page->limit;
$lim=$m->query($sql);
$pagelist=$page->fpage();
$this->assign('data',$lim);
$this->assign('list',$pagelist);
$this->display();
}
else{
$this->redirect('Login/Login');
} }
前端显示:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>业务</title>
<style type="text/css">
a:link {
text-decoration: none;
}
</style>
<script type="text/javascript">
function jump(){
window.location="/tp/index.php/Home/Add/Add";
}
</script>
<style type="text/css">
#se{
float: left;
position: absolute;
margin-left: 150px;
} </style>
</head>
<body><div id='se'><{$sess}> 您好!</div>
<div align="center" display:inline style="width: 1380px;">
<h1>业务主页</h1>
<form action="__URL__/search" method="post">
<b>查询</b> 序号:<input type="text" name="ids">
名称:<input type="text" name="name">
价格:<input type="text" name="price">
产地:<input type="text" name="source">
<input type="submit" value="搜索"></input>
</form></div><br>
<table border="1" width="1000" align="center">
<tr>
<th>序号</th>
<th>名称</th>
<th>价格</th>
<th>产地</th>
<th>操作</th>
</tr>
<volist name='data' id='vo'>
<tr>
<td><{$vo.ids}></td>
<td><{$vo.name}></td>
<td><{$vo.price}></td>
<td><{$vo.source}></td>
<td><a href="/tp/index.php/Home/User/del/ids/<{$vo.ids}>">删除</a> | <a href="/tp/index.php/Home/User/modify/ids/<{$vo.ids}>">修改</a></td>
</tr>
</volist> </table>
<div align="center"><{$list}></div>
<br>
<center>
<button onclick="jump()">添加数据</button>
</center>
</body>
</html>