溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Thinkphp中URL路徑的示例分析

發(fā)布時間:2021-10-27 17:12:00 來源:億速云 閱讀:164 作者:小新 欄目:編程語言

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

Thinkphp關(guān)于URL路徑

假如你項目首頁的URL是:www.test.com/other/Form

假如當前模塊是:Index

假如當前操作是: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

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

//項目公共目錄
$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);
//當前項目地址
$tmplContent = str_replace('__APP__',__APP__,$tmplContent);
//當前模塊地址
$tmplContent = str_replace('__URL__',__URL__,$tmplContent);
//當前項目操作地址
$tmplContent = str_replace('__ACTION__',__ACTION__,$tmplContent);
//當前頁面操作地址
$tmplContent = str_replace('__SELF__',__SELF__,$tmplContent);

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

//獲取域名或主機地址
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
//包含端口號的完整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)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI