當前位置:才華齋>計算機>php語言>

分析thinkphp常見路徑用法分析

php語言 閱讀(3.11W)

文章主要介紹了thinkphp常見路徑用法,例項分析了__PUBLIC__、__ROOT__、__APP__、__URL__、__ACTION__及__SELF__等標籤常量的.用法,需要的朋友可以參考下.就跟隨本站小編一起去了解下吧,想了解更多相關資訊請持續關注我們應屆畢業生考試網!

分析thinkphp常見路徑用法分析

本文例項分析了thinkphp常見路徑用法。分享給大家供大家參考。具體如下:

這裡介紹的標籤主要有: __root__ __self__ __action__ __url__ __app__ __public__

假如你專案首頁的URL是:

假如當前模組是:Index

假如當前操作是:index

那麼首頁完整的URL:

1 __ROOT__:/other/thinkphp/mydemo

2 __SELF__:/other/thinkphp/mydemo/Form/

3 __ACTION__: /other/thinkphp/mydemo/Form/

4 __URL__: /other/thinkphp/mydemo/Form/

5 __APP__: /other/thinkphp/mydemo/Form/

6 __PUBLIC__:/other/thinkphp/mydemo/Public

7 ../public(不區分大小寫):/other /thinkphp/mydemo/Form/Tpl/default/Public

8 APP_PUBLIC_URL:/other/thinkphp/mydemo/Form/Tpl/default/Public

9 WEB_PUBLIC_URL:/other/thinkphp/mydemo/Public

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

  複製程式碼 程式碼如下:

//專案公共目錄

$tmplContent = str_ireplace('../public',APP_PUBLIC_URL,$tmplContent);

//網站公共目錄

$tmplContent = str_replace('__PUBLIC__',WEB_PUBLIC_URL,$tmplContent);

//網站根目錄

$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);

希望本文所述對大家基於ThinkPHP框架的PHP程式設計有所幫助。