PHP脚本可以';不能使用自动加载的类
无法使用自定义自动加载程序加载UsersView类对象,导致PHP脚本出现以下错误。解决办法是什么PHP脚本可以';不能使用自动加载的类,php,autoloader,Php,Autoloader,无法使用自定义自动加载程序加载UsersView类对象,导致PHP脚本出现以下错误。解决办法是什么 Fatal error: Uncaught Error: Class 'UsersView' not found in /Applications/XAMPP/xamppfiles/htdocs/solent/common/registration/pendings.php:4 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfi
Fatal error: Uncaught Error: Class 'UsersView' not found in /Applications/XAMPP/xamppfiles/htdocs/solent/common/registration/pendings.php:4 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/solent/common/registration/pendings.php on line 4
项目结构:
classes
|_____ UsersView.php
common
|_____ autoloader.php
|_____ registration
|_____ pendings.php
Pendings.php脚本
include(“../autoloader.php”);
$PendingView=新用户视图();
$rows=$PendingView->getAllUsers();
Autoloader.php脚本
spl_autoload_寄存器('myAutoLoader');
函数myAutoLoader($className){
$path=“../classes”;
$extension=“.php”;
$fullPath=$path.$className.$extension;
如果(!file_存在($fullPath)){
返回false;
}
包括_once$fullPath;
在您的结构中,文件是否有.php
扩展名,并且是名为“UsersView”的类?可以用来查看是否包含该文件看起来缺少斜杠…因此请尝试:$fullPath=$path.'/'.$className.$extension;
或编辑$path=“../classes/”;
…还要确保include文件的扩展名为.php,因为在“Project structure:”中显示,它缺少UsersView上的.php。没有帮助,它仍然会抱怨相同的错误,但是UsersView有.php
扩展名,并且额外的//code>被添加到路径中