php包含链
这是我的问题,我有一个旧网站,其中包含一些像这样的模块,
root_dir
|-->module1
|-->module2
|-->module3
为了我的需要,我向这个结构添加一个子级别,像这样,
root_dir
|-->module1
|-->module2
|-->submodule2.1
|-->module3
我的问题是每个模块都包含一个“include.php”文件,然后包含其他模块文件,所以如果我将 include.php 的第一个路径修复为 ../include.php ,它将在第二个包含文件处崩溃...
除了复制所有文件并修复包括 ?
谢谢
Here is my problem, I ve got an old website which contains some modules like this,
root_dir
|-->module1
|-->module2
|-->module3
For my need I add a sublevel to this structure, like this,
root_dir
|-->module1
|-->module2
|-->submodule2.1
|-->module3
My problem is that each module include an "include.php" file which then include other files, so if I fix the first path of the include.php to ../include.php it will crash at the second include file...
Is there a good workaround here, besides duplicating all the files and fix the path of the include ?
Thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过对常见的 include.php 文件使用 include_once :
或包含代码曾经存在于一个共同的祖先文件中。
还是我过于简单化了?这些选项适合您吗?
Have you tried using include_once for your common include.php file:
Or including the code once in a common ancestor file.
Or am I over simplifying? Are these options to you?
“两者都是独立的,但它们包含相同的 include.php (加载站点的配置环境)”
您最好已经加载配置或使用某种方法(从中获取配置数据的工厂,全局设置 -类,...),允许加载设置,而无需了解有关实际文件结构的任何信息(从模块的角度来看)。这同样适用于您在模块中使用的所有其他内容(例如数据库对象)。
"there both standalone but they include the same include.php (which load the config environnment of the site)"
You better should have the configuration loaded already or work with some method (a factory to get configuration-data from, a global settings-class, …) that allows to load settings, without knowing anything about your actual file-structure (from a modules point of view). The same holds true for everything else you are using within the modules (like a database object).