ThinkPHP學習筆記(二)入口檔案的作用、URL控制、模板的簡單使用方式
admin.php
IndexAction.php
ThinkPHP"; } //訪問模式:path_Info//http://localhost/MyThinkPHP/admin.php?m=index&a=hello //http://localhost/MyThinkPHP/admin.php/index/hellopublic function hello(){ header("Content-Type:text/html; charset=utf-8"); echo "這是我自己的方法哦!"; } /** * 模板使用 * 大小寫一定要注意 */public function template(){//必須在對應的項目的Tpl的default下建立與當前控制器名相同的檔案夾Index//然後html檔案名稱為方法名//預設分割符方式{$content}//可以在模板指南針中進行定界符的修改$this->assign("content","小和尚下山去化齋,老和尚有交代");$this->display();//1.同級下面指定新模板//$this->display("newTemplate");//2.跨控制器的引用模板(也可以添加分組資訊)//$this->display("分組:User:verify");//3.跨皮膚引用//$this->display("[email protected]:verify");//4.全路徑輸出(在項目同級目錄建立public檔案夾)//負載檔案的位置全以主入口檔案來定位//$this->display("./public/ss.html");//display參數//$this->display("位置","utf-8","text/xml"); }}?>
conf/config.php
'配置值'//因為開啟URL重新不論是被重寫的還是沒被重寫的,都可以通過原有路徑訪問//如果想開啟rewrite模式,需要做如下操作//1.query伺服器已經開啟了Apache的rewrite模組//LoadModule rewrite_module modules/mod_rewrite.so//2.在與主入口檔案,統計目錄下,建立一個.htaccess(vi:save .htaccess;記事本:".htaccess")//如果選用模式2(rewrite)會加大伺服器的消耗'URL_MODEL'=>1,'URL_PATNINFO_MODEL'=>2,//pathinfo包含兩類//1普通模式:加上m和a:循序關聯性可以發生變化//http://localhost/MyThinkPHP/admin.php/m/index/a/index//傳值//http://localhost/MyThinkPHP/admin.php/m/index/a/index/username/zhangsan/password/password//2智能識別模組操作(預設模式就是智能識別)//http://localhost/MyThinkPHP/admin.php/index/index//傳值//http://localhost/MyThinkPHP/admin.php/index/index/username/zhangsan/password/password//修改URL分隔字元//'URL_PATHINFO_DEPR'=>'-',//修改模板左右定界符'TMPL_L_DELIM'=>'',//開啟偵錯模式//1.類比linux系統來識別大小寫//2.方法名的大小寫與模板檔案大小寫有關'APP_DEBUG'=>true,);?>
.htaccess
RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]