摘要://控制器<?php namespace app\index\controller; use think\Controller; use app\index\model\Book; class Index extends Controller { public function ind
//控制器
<?php namespace app\index\controller; use think\Controller; use app\index\model\Book; class Index extends Controller { public function index() { //獲得數(shù)據(jù) //分頁配置 $config = [ 'type' => 'bootstrap', 'var_page' => 'page', ]; //每頁數(shù)量 $num = 2; //是否是簡單分頁 $simple = false; //獲取所有分頁數(shù)據(jù):返回值是分頁對象: think\Paginate $res=Book::paginate($num, $simple, $config); //渲染分頁的HTML,返回分頁變量 $page = $res->render(); //將分頁對象賦值給模板 $this->view->assign('res', $res); //將分頁變量賦值給模板 $this->view->assign('page', $page); //渲染視圖 return $this->fetch(); } public function add(){ //渲染視圖 return $this->fetch(); } }
//模板
index.html
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題</title> <style type="text/css"> /* .main{ width: 800px; height: 600px; margin: auto; text-align: center; line-height: 600px; }*/ </style> <!-- 最新版本的 Bootstrap 核心 CSS 文件 --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <!-- 可選的 Bootstrap 主題文件(一般不用引入) --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"> <!-- 最新的 Bootstrap 核心 JavaScript 文件 --> <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script> </head> <body> <div class="main"> <table border="1"> <tr> <th>id</th> <th>圖書名</th> <th>作者</th> <th>出版時間</th> <th>分類</th> </tr> {volist name="res" id="vo"} <tr> <td>{$vo.id}</td> <td>{$vo.bName}</td> <td>{$vo.bAuthor}</td> <td>{$vo.bSetTime}</td> <td>{$vo.bClass}</td> </tr> {/volist} </table> {$page|raw} </div> </body> </html>
批改老師:查無此人批改時間:2019-02-18 09:31:32
老師總結(jié):完成的不錯,分頁的邏輯也要多熟悉,手機端的分頁和pc端分頁,可能用的邏輯不一樣,所以要多練習(xí),繼續(xù)加油