PHP不能自动加载类
我在index.php中保存了从lib文件夹加载类的_autoload()函数PHP不能自动加载类,php,url-routing,autoload,Php,Url Routing,Autoload,我在index.php中保存了从lib文件夹加载类的_autoload()函数 function __autoload($class) { if(file_exists(LIBS . $class .".php")){ require LIBS . $class .".php"; } } 我有一门仪表板课 class Dashboard extends Controller { public function __construc
function __autoload($class) {
if(file_exists(LIBS . $class .".php")){
require LIBS . $class .".php";
}
}
我有一门仪表板课
class Dashboard extends Controller {
public function __construct(){
Auth::handleLogin();
}
}
在Ubuntu12.04上使用sudo apt get安装php5和apache2,我无法自动加载该验证,可能会出现什么问题?它在我的另一台使用Bitnami XAMPP服务器的计算机上工作
这是我得到的错误:
Fatal error: Class 'Auth' not found in /var/www/app/controllers/dashboard.php on line 6
其中Auth::handleLogin();正在被调用。我有linux mint 16,我在进行对象声明时将其与名称空间一起使用 这是完美的工作
spl_autoload_register(function ($class) {
$class = str_replace("\\", "/", $class);
include $class . '.php';
});
在索引文件中
require_once 'autoload.php';
$db = new DBWork\DBWork('localhost', 'northwind', 'root', '123');
您之所以会遇到这种情况,是因为在linux中,文件系统路径区分大小写。
var_dump(LIBS.$class.“.php”,getcwd())代码>什么也没发生。。如果我死了(“进入函数”)它进入函数..你把它放在哪里了<代码>变量转储
在这种情况下应输出2个值。如果没有-您犯了错误。string(38)“/var/www/rcs/app/backend/libs/Auth.php”string(24)“/var/www/rcs/app/backend”致命错误:在第6So行的/var/www/rcs/app/backend/app/controllers/dashboard.php中找不到类“Auth”?/var/www/rcs/app/backend/libs/Auth.php
文件是否存在?别忘了它也应该跟在字母大写后面。