Thinkphp學習筆記
一、入口index.php
- <?php
- require './ThinkPHP/ThinkPHP.php';
- ?>
二、配置Conf/config.php
- <?php
- return array(
- //'配置項' => '配置值'
- 'DB_TYPE' => 'mysql', //使用的數據庫類型
- 'DB_HOST' => 'localhost',
- 'DB_NAME' => '', //數據庫名
- 'DB_USER' => '', //訪問數據庫賬號
- 'DB_PWD' => '',//訪問數據庫密碼
- 'DB_PORT' => '3306',
- 'DB_PREFIX' => '',//表前綴
- 'APP_DEBUG' => true,//調試模式開關
- 'TOKEN_ON' => true,//是否開啟令牌驗證
- 'URL_MODEL' => 1,//URL模式:0普通模式 1PATHINFO 2REWRITE 3兼容模式
- //'SHOW_PAGE_TRACE'=> true,
- //'APP_DEBUG'=>true,
- 'DB_FIELD_CACHE'=>false,
- 'HTML_CACHE_ON'=>false,
- );
- ?>
三、模板使用
結構圖
- ├─Down
- │ index.html
- │
- ├─Game
- │ index.html
- │
- ├─Index
- │ index.html
- │
- ├─LineGame
- │ index.html
- │
- ├─Public
- │ footer.html
- │ top.html
- │
- └─Video
- index.html
1、根目錄Public文件夾
__PUBLIC__
網址
__ROOT__
2、引用公用的模板文件
<include file="Public:top" />引用的是Tpl/Public/top.html
<include file="Public:footer"/>
四、系統文件
1、Lib/Action/IndexAction.class.php
執行的是模板Tpl/Index/index.html
遵循的原則是在哪個函數里執行就用哪個函數對應的模板
- <?php
- // 本類由系統自動生成,僅供測試用途
- class IndexAction extends Action {
- public function index(){
- //listvideo
- $video = M( 'video' ); // 實例化模型類
- $re=$video->where("id>=1 && id<=10")->select(); //查找
- $this->assign('listvideo',$re);
- //listdown
- $down = M( 'down' ); // 實例化模型類
- $re=$down->select();
- $this->assign('listdown',$re);
- //lm
- $lm = M( 'lm' ); // 實例化模型類
- $re=$lm->where("id>=1&&id<=10")->select(); //查找
- $this->assign('listlm',$re);
- //listjc
- $jc = M( 'jc' ); // 實例化模型類
- $re=$jc->where("id>=1&&id<=10")->select(); //查找
- $this->assign('listjc',$re);
- //display
- $this->display();
- }
- }
列表及分頁
- <?php
- // 本類由系統自動生成,僅供測試用途
- class VideoAction extends Action {
- public function index(){
- //listvideo
- $video = M( 'video' ); // 實例化模型類
- import("ORG.Util.Page");//導入分頁類
- $count = $video->count(); //計算總數
- $p = new Page($count, 10);
- $list = $video->limit($p->firstRow . ',' . $p->listRows)->order('id desc')->select();
- //$p->firstRow 當前頁開始記錄的下標,$p->listRows 每頁顯示記錄數
- $p->setConfig('header', '條數據');
- $p->setConfig('prev', "/<IMG src=/"__PUBLIC__//image//lt.gif/" align=absMiddle/>");
- $p->setConfig('next', "/<IMG src=/"__PUBLIC__//image//gt.gif/" align=absMiddle/>");
- $p->setConfig('first', '<<');
- $p->setConfig('last', '>>');
- $page = $p->show(); //分頁的導航條的輸出變量
- $this->assign("page", $page);
- $this->assign("listvideo", $list); //數據循環變量
- $this->assign('count',$count);
- //lm
- $lm = M( 'lm' ); // 實例化模型類
- $re=$lm->where("id>=1&&id<=10")->select();
- $this->assign('listlm',$re);
- //listjc
- $jc = M( 'jc' ); // 實例化模型類
- $re=$jc->where("id>=1&&id<=10")->select();
- $this->assign('listjc',$re);
- //display
- $this->display();
- }
- }
新聞熱點
疑難解答
圖片精選