0

加载文件夹中的页面时,尝试在页面上加载包含的文档时出错;

 <?php
include ('Resources/core/init.php');
include ('Resources/includes/header.php');
include ('Resources/includes/head.php');
include ('Resources/includes/footer.php');
 ?>

当我在不在网站容器文件夹中的索引页面上使用它时,它们工作正常。例如,我的索引页面的根目录是:websitename/index.php但我的其他页面位于以下文件夹中:websitename/pages/aboutus/contactus.php. 这些不是网站页面的确切名称,它只是一个示例。有谁知道我能做些什么?

4

3 回答 3

1

正如大多数评论/答案所述:绝对路径是最好的方法。或许可以从 ZenFW 等框架中汲取灵感。index.php 文件的位置是给定的,在该文件中,定义一个常量:

defined('APPLICATION_PATH') || define('APPLICATION_PATH',realpath(dirname(__FILE__)));//depending on where the index.php is in your case.

从那里开始,使用常量:

include (APPLICATION_PATH.'/Resources/core/init.php');

如果需要,realpath请在组合中添加调用:

include(realpath(APPLICATION_PATH.'/../Resources/core/ini.php');

realpath这里的文档

于 2013-05-25T14:46:25.913 回答
0

始终使用绝对路径。至少

include $_SERVER['DOCUMENT_ROOT'].'Resources/core/init.php';
于 2013-05-25T14:34:42.477 回答
0

if you want to keep using relative paths you need to use the double dot to jump back a level, for example if its 2 folders deep you would use

<?php
    include ('../../Resources/core/init.php');
    include ('../../Resources/includes/header.php');
    include ('../../Resources/includes/head.php');
    include ('../../Resources/includes/footer.php');
?>

but of course you should listen to others and create an absolute path constant and prepend it to the path if you're using multiple file locations on an app that loads the same files relative, its going to be a pain

于 2013-05-25T14:50:52.183 回答