我对理解包含路径以及如何写出来感到含糊,我知道如何在ini
文件中设置它们以及如何在功能上set_include_path
而不是如何将其设置为spl_autoload_register
无论如何都要准确无误。
所以我有一个管理员自动加载文件,我在所有标题中都包含了注册error_log
函数的文件。我只是在PHP Fatal error: Class 'Configurate' not found in
/home/~username~/public_html/testing_ini.php on line 5
文件中遇到错误。它说
public_html
所以我要找的是如何将include路径设置为始终是.:/opt/alt/php5/usr/share/pear:/opt/alt/php5/usr/share/phphome/~username~/classes/Configurate.php
目录之前的目录,无论我在哪里?
我已尝试将包含路径设置为此类
relative
但我仍然得到错误。理解这一切的任何帮助和一些提示?我吮吸spl_autoload_register
路径
根据请求的<?php
$ini = parse_ini_file("configurations.ini",true);
foreach($ini as $section) {
foreach($section as $key=>$value ) {
define("__".strtoupper($key)."__",$value);
}
}
//if(__USERNAME__ == null) {
// header("Location: /setup.php?step=1");
// exit();
//}
spl_autoload_register(function($class) {
try {
if(!file_exists("../classes/{$class}.php")){
throw new Exception("/classes/{$class}.php does not exist error on line ". __LINE__." in file ". realpath(__FILE__));
} else
require_once "../classes/{$class}.php";
} catch (Exception $ex) {
echo $ex->getMessage()."<br>";
echo $ex->getCode();
}
});
功能
{{1}}
答案 0 :(得分:0)
getcwd()
和许多其他方法对我不起作用。虽然我确实发现这个方法对我来说在任何目录中都很有用。
set_include_path(
dirname( $_SERVER["DOCUMENT_ROOT"] )
);
希望这可以帮助那些想要超出文档根目录并像我一样使用它的人。