我有一个问题,将一个函数暴露给其他php文件。我希望允许另一个php文件从本质上是根目录/index.php,或者仅仅是/index.php访问一个方法。但是,当我使用include('/ index.php ')时,它会包含来自当前目录的最新文件,即/index.php/index.php或/latest/index.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 {
}
?>root/index.php中的方法
function runMethod($log) {
}有没有一种简单的方法可以在不使用global.php文件的情况下共享该方法,或者只从根目录/index.php文件中公开该方法?
任何帮助都将不胜感激。
发布于 2016-07-30 21:25:53
像这样包括你的文件
include("../index.php"); // one folder up to the current folderhttps://stackoverflow.com/questions/38674358
复制相似问题