thinkphp3.1 分頁 注釋

來源:互聯網
上載者:User

標籤:des   style   blog   http   io   ar   color   os   sp   

有id、標題、內容、建立時間

有建立時間、標題、(分頁)

(分頁)={$page}=

 

 $count  = $Form->count();    //計算總數        $Page = new Page($count, 5);        $list   = $Form->limit($Page->firstRow. ‘,‘ . $Page->listRows)->order(‘id desc‘)->select();        // 類比設定分頁額外傳入的參數        $Page->parameter    =   ‘search=key&name=thinkphp‘;        // 設定分頁顯示        $Page->setConfig(‘header‘, ‘條資料‘);        $Page->setConfig(‘first‘, ‘<<‘);        $Page->setConfig(‘last‘, ‘>>‘);        $page = $Page->show();        $this->assign("page", $page);

 $list   = $Form->limit($Page->firstRow. ‘,‘ . $Page->listRows)->order(‘id desc‘)->select();

sql代碼

-- phpMyAdmin SQL Dump-- version phpStudy 2014-- http://www.phpmyadmin.net---- 主機: localhost-- 產生日期: 2014 年 12 月 04 日 19:08-- 伺服器版本: 5.5.38-- PHP 版本: 5.3.28SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";SET time_zone = "+00:00";/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */;/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */;/*!40101 SET @[email protected]@COLLATION_CONNECTION */;/*!40101 SET NAMES utf8 */;---- 資料庫: `page`---- ------------------------------------------------------------ 表的結構 `think_form`--CREATE TABLE IF NOT EXISTS `think_form` (  `id` smallint(4) unsigned NOT NULL AUTO_INCREMENT,  `title` varchar(255) NOT NULL,  `content` varchar(255) NOT NULL,  `create_time` int(11) unsigned NOT NULL,  PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=7 ;---- 轉存表中的資料 `think_form`--INSERT INTO `think_form` (`id`, `title`, `content`, `create_time`) VALUES(1, 你好, 你好,這是內容, 0),(2, 好好, 士大夫士大夫, 0),(3, 聖達菲, 聖達菲, 0),(4, 聖達菲, 聖達菲, 0),(5, 聖達菲, 聖達菲, 0),(6, 聖達菲, 聖達菲, 0);/*!40101 SET [email protected]_CHARACTER_SET_CLIENT */;/*!40101 SET [email protected]_CHARACTER_SET_RESULTS */;/*!40101 SET [email protected]_COLLATION_CONNECTION */;

配置代碼

<?phpreturn array(    //‘配置項‘=>‘配置值‘    //‘USERNAME‘=>‘admin‘, //賦值    //資料庫配置資訊    ‘URL_MODEL‘         =>  1,    ‘URL_PATHINFO_DEPR‘ =>  ‘/‘,        ‘DB_TYPE‘   => ‘mysql‘, // 資料庫類型        ‘DB_HOST‘   => ‘localhost‘, // 伺服器位址        ‘DB_NAME‘   => ‘page‘, // 資料庫名        ‘DB_USER‘   => ‘root‘, // 使用者名稱        ‘DB_PWD‘    => ‘root‘, // 密碼        ‘DB_PORT‘   => 3306, // 連接埠        ‘DB_PREFIX‘ => ‘think_‘, // 資料庫表首碼         //其他項目配置參數        // ...);?>

控制器代碼

<?phpclass IndexAction extends Action {    public function index() {        import("@.ORG.Page");       //匯入分頁類        $Form   =   M(‘Form‘);      //執行個體化form表        $count  = $Form->count();    //計算表內記錄的總數        $Page = new Page($count, 5); //一頁中的數量為5        $list   = $Form->limit($Page->firstRow. ‘,‘ . $Page->listRows)->order(‘id desc‘)->select();        // 查詢form表,根據id降序查詢,limi用於限制查詢結果數量,firstRow第一行,listRows表行        $Page->parameter    =   ‘search=key&name=thinkphp‘;//parameter參數        // 設定分頁顯示        $Page->setConfig(‘header‘, ‘條資料‘);//頁面顯示為:6條資料        $Page->setConfig(‘first‘, ‘<<‘);        $Page->setConfig(‘last‘, ‘>>‘);        $page = $Page->show();        $this->assign("page", $page);        $this->assign("list", $list);        $this->display();    }}

顯示頁代碼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   <html xmlns="http://www.w3.org/1999/xhtml">   <head>   <title>ThinkPHP樣本: 分頁操作</title>      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />       <style type="text/css">    *{ padding: 0; margin: 0;font-size:16px; font-family: "微軟雅黑"}     div{ padding: 3px 20px;}     body{ background: #fff; color: #333;}    h2{font-size:36px}    div.result{border:1px solid #d4d4d4; background:#FFC;color:#393939; padding:8px 10px;float:auto; width:450px;margin:2px}    a{text-decoration:none; color:gray;}    a:hover{color:#F60;}    div.page{border:1px solid #d4d4d4; background:#333;color:white; padding:5px 15px;float:auto; width:450px;margin:2px;text-align:right}    </style></head>   <body>   <div ><h2>ThinkPHP樣本:分頁操作</h2><div class="result">可以更改設定檔中的<b>URL_MODEL</b>和<b>URL_PATHINFO_DEPR</b>參數查看分頁連結的區別。</div><table cellpadding=3 cellspacing=5><volist name="list" id="vo"><tr><td style="border-bottom:1px solid silver;"><span style="color:gray">[ {$vo.create_time|date=‘Y-m-d H:i:s‘,###} ]</span> {$vo.title} </td></tr></volist><tr>        </tr></table><div class="result page">{$page}</div></div> </body>   </html>

 原版:

sql代碼

CREATE TABLE IF NOT EXISTS `think_form` (  `id` smallint(4) unsigned NOT NULL AUTO_INCREMENT,  `title` varchar(255) NOT NULL,  `content` varchar(255) NOT NULL,  `create_time` int(11) unsigned NOT NULL,  PRIMARY KEY (`id`) ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 ;

地址:

http://www.thinkphp.cn/extend/240.html

thinkphp3.1 分頁 注釋

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.