我有一個問題暴露了一個函數到其他php文件。我想允許另一個php文件從本質上root/index.php或者/index.php訪問一個方法。然而,當我使用包括('/ index.php'),而是包括當前目錄的index.php文件,即/search/index.php或/latest/index.php從外部root/index.php提供php方法
最終,即時嘗試解決的是如何調用存儲在從根/ mydirectory中/的index.php我的index.php文件的方法:
//root/mydirectory/index.php
<?php
include('/index.php');
if (isset($_GET['id'])) {
runMethod($log);//function i want to call, defined in regular /index.php file
} else {
}
?>
法根/ index.php文件
function runMethod($log) {
}
是否有共享的簡單方法這個方法沒有使用global.php文件,或只暴露root/index.php文件中的方法?
任何幫助,將不勝感激。
你的意思'方法,在課堂上method'或你的意思是一個函數? – RiggsFolly
一個函數對不起,我會盡力在描述中明確說明 – D3181
請提供包含文件的絕對路徑。使用'__FILE__'獲取當前文件路徑和'dirname(__ FILE __)'以獲得當前文件夾的名稱,您正在運行腳本 – C2486