使php包含在子目录中的工作 [英] Making php includes work in a sub-directory

查看:130
本文介绍了使php包含在子目录中的工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我在url / admin上为自定义博客创建了一个管理界面。



我可以使用相同的包含(包括自动加载),作为根目录。



如果可能,我也希望能够自动更正导航中的链接,以便它们到达index.php / />

感谢Nico

解决方案

最佳做法是定义一个包含所有目录所在目录的ABSOLUTE_PATH常量。之后,您可以简单地复制和粘贴所有内容,因为它定义了完整路径,它不会从目录更改为目录。



示例

  define(ABS_PATH,$ _SERVER ['DOCUMENT_ROOT']); 



define(ABS_PATH,dirname(__ FILE__));
//将路径定义为文件所在的目录。

然后在任何点,你可以简单地做到这一点包括一个文件

  include(ABS_PATH。/ path / to / file); 


Ok, I am creating an admin interface for my custom blog at the url /admin.

Is it possible for me to be able to use the same includes (including autoload), as the root directory.

If possible, I would also like to be able to automatically correct the links in the navigation so that they go that index.php in / changes to ../index.php when accessed from /admin.

Thanks, Nico

解决方案

The best practice for this is to define a 'ABSOLUTE_PATH' constant that contains the directory that everything is located under. After that, you can simply copy and paste everything, because it is defining the 'full' path, which doesn't change from directory to directory.

Example

define("ABS_PATH", $_SERVER['DOCUMENT_ROOT']);

or

define("ABS_PATH", dirname(__FILE__));
// This defines the path as the directory the file is in.

Then at any point you can simply do this to include a file

include(ABS_PATH . "/path/to/file");

这篇关于使php包含在子目录中的工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆