abstract:前端用的Bootstrap3分页用的think\db\paginate方法,之所以可以Student::paginate这样使用,是因为Student::等价于Db::table('student')模型<?phpnamespace app\demo\model; use think\Model;class Student extends Model{}控制器<
前端用的Bootstrap3
分页用的think\db\paginate方法,之所以可以Student::paginate这样使用,是因为Student::等价于Db::table('student')
模型
<?php
namespace app\demo\model;
use think\Model;
class Student extends Model
{
}
控制器
<?php
namespace app\demo\controller;
use think\Controller;
use think\Facade\View;
use app\demo\model\Student;
class Demo7 extends Controller
{
public function test1()
{
$content = '<h3 style="color: red;">学习PHP中文网的视频教程中</h3>';
// 这里也可以用静态代理的方法写
return View::display($content);
}
public function test3()
{
$data = Student::all();
$this->view->assign('data',$data);
return $this->view->fetch();
}
public function test4()
{
// 使用分页方法
$data = Student::paginate(5);
$this->view->assign('data',$data);
return $this->view->fetch();
}
}
视图
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>{$title|default='默认标题'}</title>
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="/static/js/bootstrap.min.js"></script>
</head>
<body>
<div>
<div>
<div></div>
<div>
<h2>考试信息</h2>
<table class="table table-bordered table-default text-center">
<tr>
<td>序号</td>
<td>昵称</td>
<td>邮箱</td>
<td>课程</td>
<td>分数</td>
</tr>
{volist name='data' id='list'}
<tr>
<td>{$list.id}</td>
<td>{$list.name}</td>
<td>{$list.email}</td>
<td>{$list.course}</td>
<td>
{if $list.grade>=60}
<span style="color: green;">及格</span>
{else /}
<span style="color: red;">不及格</span>
{/if}
</td>
</tr>
{/volist}
</table>
</div>
<div></div>
<div>
<!--开启分页条-->
{$data|raw}
</div>
</div>
</div>
</body>
</html>
Correcting teacher:西门大官人Correction time:2019-03-03 13:16:48
Teacher's summary:思考一下,查询分页数据的时候,如何带上查询条件?