管理包含文件

时间:2013-08-03 11:52:38

标签: php include

我不想将所有包含文件放在必要页面的顶部,而是将它们包含在一个包含文件中,然后只链接到将加载相关包含文件的那些文件。

以下适用于根文件夹中的任何文档,但如果我在子文件夹中它不是,有没有办法识别是否在子文件夹中并重置它以搜索根文件夹?

<?php

// Define the core paths
// Define them as absolute paths to make sure that require_once works as expected

// DIRECTORY_SEPARATOR is a PHP pre-defined constant
// (\ for Windows, / for Unix)
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);

// define the location of the default includes path
defined('INC_PATH') ? null : define('LIB_PATH', 'bugs'. DS . 'includes');

// load config file first
require_once(INC_PATH.DS.'config.php');

// load basic functions next so that everything after can use them
require_once(INC_PATH.DS.'functions.php');

// load core objects
require_once(INC_PATH.DS.'database.class.php');

// load database-related classes
require_once(INC_PATH.DS.'bug.class.php');
require_once(INC_PATH.DS.'users.class.php');

?>

这是基于一个教程,但这是在一个本地文件夹而不是像我这样的网络服务器所以我不得不稍微调整一下,也许我已经过度复杂了?

0 个答案:

没有答案
相关问题