模板标签、分页

原创 2018-12-20 19:34:41 242
摘要:<?php  namespace app\index\controller; use think\Controller; use app\index\model\Score as ScoreModel; use think\facade\Request; class Score extends 
<?php 
namespace app\index\controller;
use think\Controller;
use app\index\model\Score as ScoreModel;
use think\facade\Request;
class Score extends Controller
{
	//循环标签
	public function demo1()
	{
		$scores = ScoreModel::all(function($query){
			$query->field(['id','name','sex','java','php']);
		});
		$this->view->assign('scores', $scores);
		return $this->view->fetch();
	}

	//分页查询
	public function demo2()
	{
		//分页配置
		$config = [
			'type' => 'bootstrap',
			'var_page' => 'page',
			
		];
		//每页显示记录数量
		$num = 3;

		//是否是简单分页
		$simple = false;

		//获取所有分页数据:返回值是分页对象: think\Paginate
		$paginate = SocreModel::paginate($num, $simple, $config);

		//渲染分页的HTML 返回分页变量
		$page = $paginate->render();

		//将分页对象赋值给模板
		$this->view->assign('scores', $paginate);

		//将分页变量赋值给模板
		$this->view->assign('page', $page);

		//渲染模板
		return $this->view->fetch();	

	}
}


批改老师:天蓬老师批改时间:2018-12-20 20:40:10
老师总结:分页是有一个分页对象, 文件操作也是有一个文件类, tp中很多操作,都是这样实现的

发布手记

热门词条