Thinkphp中URL路徑的示例分析

這篇文章主要介紹Thinkphp中URL路徑的示例分析,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!

創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供會(huì)寧網(wǎng)站建設(shè)、會(huì)寧做網(wǎng)站、會(huì)寧網(wǎng)站設(shè)計(jì)、會(huì)寧網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、會(huì)寧企業(yè)網(wǎng)站模板建站服務(wù),十余年會(huì)寧做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

Thinkphp關(guān)于URL路徑

假如你項(xiàng)目首頁的URL是:www.test.com/other/Form

假如當(dāng)前模塊是:Index

假如當(dāng)前操作是:index

那么首頁完整的URL:www.test.com/other/Form/index.php/Index/index

__ROOT__:/other/thinkphp/mydemo
__SELF__:/other/thinkphp/mydemo/Form/index.php
__ACTION__: /other/thinkphp/mydemo/Form/index.php/Index/index
__URL__: /other/thinkphp/mydemo/Form/index.php/Index
__APP__: /other/thinkphp/mydemo/Form/index.php
__PUBLIC__:/other/thinkphp/mydemo/Public
../public(不區(qū)分大小寫):/other /thinkphp/mydemo/Form/Tpl/default/Public
APP_PUBLIC_URL:/other/thinkphp/mydemo/Form/Tpl/default/Public
WEB_PUBLIC_URL:/other/thinkphp/mydemo/Public

模板中對(duì)路徑部分的操作是這樣子的,PHP代碼:

//項(xiàng)目公共目錄
$tmplContent = str_ireplace('../public',APP_PUBLIC_URL,$tmplContent);
//網(wǎng)站公共目錄
$tmplContent = str_replace('__PUBLIC__',WEB_PUBLIC_URL,$tmplContent);
//網(wǎng)站根目錄
$tmplContent = str_replace('__ROOT__',__ROOT__,$tmplContent);
//當(dāng)前項(xiàng)目地址
$tmplContent = str_replace('__APP__',__APP__,$tmplContent);
//當(dāng)前模塊地址
$tmplContent = str_replace('__URL__',__URL__,$tmplContent);
//當(dāng)前項(xiàng)目操作地址
$tmplContent = str_replace('__ACTION__',__ACTION__,$tmplContent);
//當(dāng)前頁面操作地址
$tmplContent = str_replace('__SELF__',__SELF__,$tmplContent);

測試網(wǎng)址:http://localhost/blog/testurl.php?id=5

//獲取域名或主機(jī)地址
echo $_SERVER['HTTP_HOST']."
"; #localhost
//獲取網(wǎng)頁地址
echo $_SERVER['PHP_SELF']."
"; #/blog/testurl.php
//獲取網(wǎng)址參數(shù)
echo $_SERVER["QUERY_STRING"]."
"; #id=5
//獲取用戶代理
echo $_SERVER['HTTP_REFERER']."
";
//獲取完整的url
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
#http://localhost/blog/testurl.php?id=5
//包含端口號(hào)的完整url
echo 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
#http://localhost:80/blog/testurl.php?id=5
//只取路徑
$url='http://'.$_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"];
echo dirname($url);
#http://localhost/blog

以上是“Thinkphp中URL路徑的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!

文章標(biāo)題:Thinkphp中URL路徑的示例分析
文章起源:http://muchs.cn/article28/pppsjp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)頁設(shè)計(jì)公司、網(wǎng)站導(dǎo)航網(wǎng)站維護(hù)、營銷型網(wǎng)站建設(shè)網(wǎng)站改版、微信公眾號(hào)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營