php的include_path for includes以./开头

Rud*_*die 1 php include include-path

在我的PHP框架中,我想使用另一个PHP框架的几个函数.其他框架只有一个门户脚本(index.php).它从那里做所有事情(引导程序,呼叫控制器和动作等).另一个框架包括以./开头的所有文件

另一个框架的index.php:

include './inc/bootstrap.php';
Run Code Online (Sandbox Code Playgroud)

在bootstrap.php中:

include './inc/configs.php';
include './inc/database.php';
Run Code Online (Sandbox Code Playgroud)

等等

因此看起来所有包含都与index.php所在的文件夹相关.

有没有办法设置环境,所以我可以从另一个文件夹(我的框架中的某个地方,所以一个完全不同的文件夹,而不是门户网站脚本)引导框架?

include_path包括.和我已经尝试了include_path中的其他框架的文件夹,但没有改变任何东西.

我猜它是./包含,但我不能改变它们(另一个框架不是我的框架的一部分,并将在一段时间内更新).有没有办法围绕他们(或者我做错了)?

Fra*_*ani 5

路径开头.或/忽略include_path,因为它们是相对于工作目录的.

所以唯一的方法是使用PHP函数chdir更改工作目录:

在你的框架中:

chdir('/path/of/the/other/framework'); // change the working directory
require '/path/of/the/other/framework/bootstrap.php'; 

// optionally you can reset the working directory
chdir(dirname(__file__));
Run Code Online (Sandbox Code Playgroud)