簡體   English   中英

如何使用包含或最佳實踐在PHP中定義路徑

[英]How to define the path in PHP using include or best practices

大家好

我正在我的兄弟站點上工作,在那里他在“ publich_html”上獲得了“ BreadCrumbs.php”,那里也有index.html。

在public_html中,我也很少有“關於我們”,“職業”和html文件之類的文件夾。 現在,當我將“ BreadCrumbs.php”鏈接放置到Index.html文件時,它顯示結果,但是當我將相同的鏈接放置到(即,關於“關於我們”文件夾中的us.html時,它不起作用。

我只是想知道我應該如何定義包含路徑,以便它也可以與Folder一起使用。 像這樣 ...

Public_html
|
| __ index.html
| __ BreadCrumbs.php
| __關於我們> aboutus.html (文件位於文件夾中) |
| __職業> career.html (文件位於文件夾中)

幾乎沒有什么幫助。

添加到我的帖子我有這個代碼

include_once('class.breadcrumb.inc.php');  
$breadcrumb = new breadcrumb;
echo "<p>".$breadcrumb->show_breadcrumb()."</p>";

它僅適用於index.html文件。 不適用於文件夾中的其他文件

謝謝

我使用以下方法來解決該問題:

$about = HTTP_SERVER . 'folder/about.html';

HTTP_SERVER會將您的鏈接從about.html轉換為http://www.yourhost.com/about.html

注意:除非您使用Mod Rewrite將php擴展名轉換為html,否則僅在帶有php擴展名(* .php)的頁面中需要PHP代碼。

您可以考慮目錄結構,並從更深層次進行包含。

在public_html中: include("./class.breadcrumb.inc.php");

在子文件夾中: include("../class.breadcrumb.inc.php");

希望這可以幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM