一、TP框架的下載和安裝
Tp框架下載網址:http://www.thinkphp.cn/
在wamp的www目錄下創建一個目錄tpshop目錄
1. 將下載好的包壓縮后將文件包里的所有文件復制到創建項目的根目錄(tpshop)中
|Application
|Public
|ThinkPHP
|.htaccess
|composer.json
|index.php
|README.md
2.index.php就是我們要創建的項目的入口文件
// 檢測PHP環境
if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !');
// 開啟調試模式 建議開發階段開啟 部署階段注釋或者設為false
define('APP_DEBUG',True);
//定義項目名稱
define('APP_NAME','App');
// 定義項目路徑
define('APP_PATH','./Application/');
// 引入ThinkPHP入口文件
require './ThinkPHP/ThinkPHP.php';
3.訪問localhost/tpshop/index.php/App/Index/index此時項目就創建好了
Common 項目公共文件目錄 一般放置項目的公共函數
Conf 項目的配置目錄 放置所有的配置文件
Lib 項目類庫目錄 包括Action和Model子目錄
Tpl 項目的模板目錄 支持模板主題
Extend 框架的擴展目錄
4.錯誤日志位置
Runtime/logs/ cache 編譯目錄
5.Tp訪問地址參數
http://localhost/tpshop/index.php/APP/Index/index/10;
6.模板標簽配置和數據庫配置!模板標簽默認是{};也可以進行更改、在配置文件中
return array(
/**************定界符***********/
'TMP_L_DELIM' => '<{',
'TMP_R_DELIM' =>'}>',
/**********************/
'DB_TYPE' => '', // 數據庫類型
'DB_HOST' => '', // 服務器地址
'DB_NAME' => '', // 數據庫名
'DB_USER' => '', // 用戶名
'DB_PWD' => '', // 密碼
'DB_PORT' => '', // 端口
'DB_PREFIX' => '', // 數據庫表前綴
'DB_PARAMS' => array(), // 數據庫連接參數
'DB_DEBUG' => TRUE, // 數據庫調試模式 開啟后可以記錄SQL日志
'DB_FIELDS_CACHE' => true, // 啟用字段緩存
'DB_CHARSET' => 'utf8', //
);
7.__ROOT__輸出的是項目根目錄; /tpshop
__APP__當前項目的路徑 /tpshop/index.php
__URL__當前項目的模塊 /tpshop/index.php/Index
__ACTION__當前項目的操做的URL地址 /tpshop/index.php/Index/index
__PUBLIC__ 會被替換成當前項目的 Public目錄
__SELF__ 會替換成當前的URL
注意:tp中靜態資源一定要網站的絕對路徑
8.Thinkphp支持四種URL模式
① 普通模式
http://localhost/test/index.php?m=Index&a=index&id=10
獲取模塊和方法名稱
MODULE_NAME
ACTION_NAME
②pathinfo模式
http://laocalhost/test/index.php/Index/index/id/10;
③rewrite模式
http://localhost/test/Index/index/id/10;
使用rewrite模式一定要修改apache配置文件
1)開啟 LoadModule rewrite_module modules/mod_write.so
2)修改網站根目錄支持rewrite地址重寫
<Directory "C://AppServ/www">
Options Indexs FolloewSymLinks
#一定要把multivews去掉
AllowOverride All
Order allow,deny
Allow from all
</Directory>
3)重啟apache
4) 把.htaccess放到入口文件的目錄下:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>
④兼容模式
http://localhost/test/?s=/Index.index/id/10;
9.配置中默認訪問模塊和方法
'DEFULT_MODULE' => 'Index' //默認模塊名稱
'DEFAULT_ACTION' => 'index' //默認操作方法
10 讀取配置
C(‘參數名稱’); //獲取config中的設置的參數值
11.顯示模板 $this->display(); 分配變量到模板:$this->assign('data',$data);
本模塊地址跳轉$this->success('ok','index');
跨模塊跳轉:$this->success('添加成功',U('Login/index'));
重定向 $this->redirect();
12 支持多函數過濾
"DEFAULT_FILIER" => "trim,htmlspecialchars,strip_tags";