1

I'm having dubts on my website's structure. I've a config, lib and public folders in the root. config contains the config.php and other similiar, lib contains all php/html content (header, each page content, footer etc), while public folder contains all the subfolders for each page with the index.php inside. I did this for the url... Anyway, each of these index.php set their page name in a variable and call the config.php file and a module.php for the whole content. My problem is that since I have multi level subdirectory (news/sport/football) each index.php have different config path to call. The "deepest" files have many "../" before config/config.php.

Here's the index.php inside public/news/:

<?php  
require '../../config/config.php';


$MainPage = 'news';
$CurPage = 'news';


include_once(LIB_PATH. 'modules.php');  
?>

So, is there any way to get the absolute root dir so that the path is the same in all files? Also, is this structure correct?

4

2 回答 2

0

您应该能够使用绝对路径从任何地方调用 config.php。

include "/config/config.php";

您不能这样做,因为 PHP 的 ini_path 不包括您的目录。

尝试阅读有关在哪里/如何将目录添加到 php.ini 路径的答案。

于 2013-04-28T09:25:56.020 回答
-1
require $_SERVER['DOCUMENT_ROOT'].'/config/config.php';
于 2013-04-27T17:50:08.557 回答