看了看推薦的分頁類的使用,還是很簡單的,可是自己去嘗試改寫生成的分頁類結構就會很麻煩,總是不成功,後來發現手冊裏面還有這個
就說你想重寫分頁類,就需要這樣做
趕緊實踐了一下,先改這裏的provider.php
然後新建這個app/common/MyPaginator.php 然後在裏面很簡單寫一下這個
<?php namespace app\common; use think\paginator\driver\Bootstrap; class MyPaginator extends Bootstrap { /** * 渲染分頁html * @return mixed */ public function render() { if ($this->hasPages()) { if ($this->simple) { return sprintf( '<div class="pagination"><ul>%s %s</ul></div>', $this->getPreviousButton(), $this->getNextButton() ); } else { return sprintf( '<div class="pagination"><ul>%s %s %s</ul></div>', $this->getPreviousButton(), $this->getLinks(), $this->getNextButton() ); } } } }
只要做個繼承,然後重寫render方法即可.
然後控制器這邊這樣用
頁面上面直接
<?php namespace app\model; use think\Model; class XXXModel extends Model { protected $name = 'ticket'; public function list_data(array $where = []) { return self::where($where)->field("id, status, add_time")->order('id', 'desc')->paginate(10); } }
則有就能生成分頁了
效果如圖
如果這樣寫 paginate(10, true)
就能獲得簡單的分頁 上一頁 下一頁那種
看來還是要多看手冊呢