thinkphp数组分页

 1 前几天做项目,用到thinkphp数组分页,现将代码记录如下:
 2 
 3 public function arrayPaging($list)
 4 
 5 {
 6 
 7 //定义每页显示数
 8 
 9 $per=10;
10 
11 //得到数组总数
12 
13 $count=count($list);
14 
15 //创建分页对象
16 
17 $page=new \Think\Page($count,$per);
18 
19 //利用array_slice函数分页
20 
21 $list=arrayslice($list,$page−>firstRow,$page->lastRows);
22 
23 //分页显示输出
24 
25 $show=$page->show();
26 
27 //给模板赋值并输出
28 
29 $this−>assign(′per′,$per);
30 
31 $this−>assign(′count′,$count);
32 
33 $this−>assign(′page′,$show);
34 
35 $this−>assing(′list′,$list);
36 
37 $this->display();
38 
39 }

 

posted @ 2018-07-29 10:52  易10  阅读(236)  评论(0编辑  收藏  举报