php 的 include_path 包含以 ./ 开头的内容
在我的 PHP 框架中,我想使用另一个 PHP 框架的几个功能。另一个框架只有一个门户脚本 (index.php)。从那里它执行所有操作(引导、调用控制器和操作等)。另一个框架包含以 ./ 开头的所有文件
另一个框架的index.php:
include './inc/bootstrap.php';
在bootstrap.php中:
include './inc/configs.php';
include './inc/database.php';
等等等等
所以看起来所有包含内容都相对于index.php所在的文件夹。
有什么方法可以设置环境,以便我可以从另一个文件夹引导框架(在我的框架内的某个位置,所以是一个完全不同的文件夹,而不是门户脚本)?
include_path
包含 .
并且我也尝试过使用 include_path 中其他框架的文件夹,但这没有改变任何内容。
我猜这是 ./ 包含,但我无法更改它们(另一个框架不是我的框架的一部分,并且会在某个时候更新)。有没有办法绕过它们(或者我做错了)?
In my PHP framework, I want to use several functions of another PHP framework. That other framework has only one portal script (index.php). From there it does everything (bootstrap, call controllers and actions etc). The other framework includes all its files starting with ./
The other framework's index.php:
include './inc/bootstrap.php';
In bootstrap.php:
include './inc/configs.php';
include './inc/database.php';
etc etc
So it looks like all the includes are relative to the folder index.php is in.
Is there any way to set up the environment so I can bootstrap the framework from another folder (somewhere within my framework, so a completely different folder and not the portal script)?
include_path
includes .
and I've tried it with the other framework's folder in the include_path as well but that didn't change anything.
I'm guessing it's the ./ includes, but I can't change those (the other framework isn't part of my framework and will be updated some time). Is there a way around them (or am I doing it plain wrong)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以 . 开头的路径。或 / 忽略 include_path 因为它们是相对于工作目录的。
唯一的方法是使用 PHP 函数 chdir 更改工作目录:
所以 你的框架:
path starting with . or / ignore the include_path because they are relative to the working directory.
So the only way is to change the working directory using the PHP function chdir:
In your framework:
当您要包含其他框架的引导程序文件时,您需要
chdir()
首先进入该目录,然后您可以包含它,并且它将执行的所有后续包含都将正确地相对于引导文件。When you go to include the other framework's bootstrap file, you'll need to
chdir()
into that directory first, then you can include it, and all the subsequent includes it will do will be properly relative to the bootstrap file.您应该可以使用
set_include_path( $path_to_include_files )
来完成此操作。如果您仍然遇到问题,则可能意味着脚本中的另一个位置将include_path
设置为另一个值。You should be able to do this with
set_include_path( $path_to_include_files )
. If you still have problems it might mean that there is another place in your script that is setting theinclude_path
to another value..
│— index.php
│— t1
│ │— a
│ └─ b
└─ t2
|— b
└─ c
源
.
│— index.php
│— t1
│ │— a
│ └─ b
└─ t2
|— b
└─ c
source