????://控制器<?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ù) //分頁(yè)配置 $config = [ 'type' => 'bootstrap', 'var_page' => 'page', ]; //每頁(yè)數(shù)量 $num = 2; //是否是簡(jiǎn)單分頁(yè) $simple = false; //獲取所有分頁(yè)數(shù)據(jù):返回值是分頁(yè)對(duì)象: think\Paginate $res=Book::paginate($num, $simple, $config); //渲染分頁(yè)的HTML,返回分頁(yè)變量 $page = $res->render(); //將分頁(yè)對(duì)象賦值給模板 $this->view->assign('res', $res); //將分頁(yè)變量賦值給模板 $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>無(wú)標(biāo)題</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>圖書(shū)名</th> <th>作者</th> <th>出版時(shí)間</th> <th>分類(lèi)</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>
?? ???:查無(wú)此人?? ??:2019-02-18 09:31:32
???? ??:完成的不錯(cuò),分頁(yè)的邏輯也要多熟悉,手機(jī)端的分頁(yè)和pc端分頁(yè),可能用的邏輯不一樣,所以要多練習(xí),繼續(xù)加油