Thinkphp5.1 文件引入
1、視圖文件中引入其他的視圖文件
文件目錄如下圖:
需要實現在index.html中引入public文件夾下面的四個html模板文件,index.html引入代碼如下:
{include file= /public/_meta }{include file= /public/_header }{include file= /public/_menu } p 中間部分填寫頁面特有的內容 /p {include file= /public/_footer }
通過這種方式,能夠將通用的,不常改變的內容抽取出來,避免了代碼冗余。
2、視圖文件中引入public文件下的靜態文件
文件目錄如下圖:
我們需要在index.html的視圖模板中引入一些靜態的css、js文件,這些文件一般存放在public目錄下,我們現在采用相對路徑的方式引入這些文件,index.html文件引入代碼如下:
link rel= stylesheet type= text/css href= /../static/Hadmin/static/h-ui/css/H-ui.min.css rel= external nofollow / link rel= stylesheet type= text/css href= /../static/Hadmin/static/h-ui.admin/css/H-ui.admin.css rel= external nofollow / link rel= stylesheet type= text/css href= /../static/Hadmin/lib/Hui-iconfont/1.0.8/iconfont.css rel= external nofollow / link rel= stylesheet type= text/css href= /../static/Hadmin/static/h-ui.admin/skin/default/skin.css rel= external nofollow id= skin / link rel= stylesheet type= text/css href= /../static/Hadmin/static/h-ui.admin/css/style.css rel= external nofollow /
在我的測試項目中,上述代碼引入成功。若實際實踐過程中引入失敗,不要急,介紹個方便調試的辦法:首先,刷新你的網頁;第二步,右鍵查看網頁源代碼;第三步,復制對應的文件引入鏈接,在新的頁面中打開;第四步,檢查瀏覽器實際識別到的文件路徑是哪里,通過調整url調整到正確的文件路徑,即能正確訪問到文件內容為止;第五步,參照這個能夠使用的文件路徑對現有的路徑進行改進即可。
3、自己定義全局變量,在模板文件中使用
需要說明一下,tp5.1更改了配置變量名,更改如下:
tpl_replace_string = [ __STATIC__ = /static , ],
具體實現步驟:
1、在Config/template.php中加入自己需要定義的常量。
2、直接在模板中使用即可,如下:
link rel= stylesheet type= text/css href= __STATIC__/Hadmin/static/h-ui/css/H-ui.min.css rel= external nofollow /
這個路徑具體設置,根據你的實際項目目錄而定,自行更改即可。
以上就是本文的全部內容,希望對大家的學習有所幫助,更多相關內容請關注PHP !
相關推薦:
如何利用ThinkPHP整合datatables實現服務端分頁
ThinkPHP模版引擎的變量輸出的解析
以上就是關于thinkphp5.1 文件引入路徑的問題的詳細內容,PHP教程
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答