企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
### 数据分页 添加分页扩展 ~~~ composer require luojiangtao/page dev-master ~~~ 引入 ~~~ use luojiangtao\page\Page; ~~~ 控制器 ~~~ /** * 文章列表 */ public function articleList() { // 搜索关键字 $keyword = Request::instance()->request('keyword'); // 防止报错 $where[] = ['status', '=', 1]; if ($keyword) { // 模糊匹配标题 $where[] = ['title', 'like', "%{$keyword}%"]; } // 统计文章总数 $count = (new Model('article'))->where($where)->count(); // 分页 $page = new Page($count, 10); // 获取文章 $article = (new Model('article'))->order('article_id DESC')->where($where)->limit($page->start_row . ',' . $page->page_size)->select(); foreach ($article as $key => $value) { $categoryModel = new Model('category'); $commentModel = new Model('comment'); $article[$key]['category_name'] = $categoryModel->where(['category_id', '=', $value['category_id']])->getField('category_name'); $article[$key]['comment_number'] = $commentModel->where(['article_id', '=', $value['article_id']])->count(); } // 分配变量到前台模版 $this->assign('article', $article); // 分页 $this->assign('page', $page->show()); // 载入模版 return $this->fetch(); } ~~~ 模版页面使用 ~~~ {$page} ~~~ 输出结果: ~~~ <a class="page-disable">首页</a> <a class="page-disable">«</a> <a class="page now-page" href="/frame/index.php?&amp;p=1">1</a> <a class="page-disable">»</a> <a class="last-page page-disable">尾页</a> ~~~