批改状态:未批改
老师批语:
<?php
/**
* @Author: owlcity
* @Date: 2018-05-31 11:12:33
* @Last Modified by: owlcity
* @Last Modified time: 2018-05-31 17:39:51
*/
namespace app\index\controller;
use think\Controller;
use app\index\model\Test as TestModel;
class Test extends Controller{
public function demo1(){
$staffs = TestModel::all(function($query){
$query->field(['staff_id','name','sex','age','salary']);
// ->where('salary < 100');
});
// dump($staffs);
// 用all则不行
// all select find一样 都是查询方法需要查询条件
// 不指定查询条件也可以
$employ = TestModel::paginate(7);
// $config = [
// 'type'=> 'bootstrap',
// 'var_page'=> 'page'
// ];
// $num = 10;
// $simple = false;
// $employ = TestModel::paginate($num,$simple,$config);
$page = $employ->render();
$this->view->assign('staff',$employ);
$this->view->assign('page',$page);
return $this->view->fetch();
}
}前端模版
{load href="/static/bootstrap/css/bootstrap.css" }
<h2 class="text-center">员工信息表</h2>
<div class="container">
<div class="col-md-8 col-md-offset-2">
<table class="table table-bordered table-hover text-center">
<tr class="info">
<td>id</td>
<td>姓名</td>
<td>性别</td>
<td>年龄</td>
<td>收入</td>
</tr>
{empty name="staff"}
<h4>暂无数据</h4>
{else /}
{volist name="staff" id="item"}
<tr>
<td>{$item.staff_id}</td>
<td>{$item.name}</td>
<td>{$item.sex}</td>
<td>{$item.age}</td>
<td>{$item.salary}</td>
</tr>
{/volist}
{/empty}
</table>
<div class="text-center">{$page|raw}</div>
</div>
</div>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号