php - 致命错误:未捕获的错误:在 C:\apache\htdocs\inventory_manager\app\public\index.php:17 中找不到类“订单”
问题描述
我正在创建一个应用程序以在 composer.json 中使用自动加载来加载我的类文件。我得到
Fatal error: Uncaught Error: Class 'Order' not found in C:\apache\htdocs\inventory_manager\app\public\index.php:17
我在 vendor/composer/autoload_psr4.php 中检查了 $vendorDir 文件夹相对于我的 $baseDir 的路径,并且它是正确的。我已经检查过有类似问题的线程,但仍然存在。提前致谢
这是我的 composer.json 文件
{
"name": "inventory manager",
"description": "Inventory Management System",
"require": {
"phpmailer/phpmailer": "~6.0"
},
"autoload": {
"psr-4": {
"App\\": "app"
}
}
}
这是我的文件夹结构
|---inventory_manager
|---app
|---Model
|---DatabaseObject.php
|---Order.php
|---Product.php
|---public
|---assets
|---css
|---index.php
|---vendor
|---composer.json
订单.php
namespace App;
class Order
{
private $name;
private $brand;
private $shape;
function __construct($name,$brand, $shape)
{
$this->name = $name;
$this->brand = $brand;
$this->shape = $shape;
}
public function toString()
{
return "{$this->name}, {$this->brand}, {$this->shape}";
}
}
索引.php
<?php
require '../../vendor/autoload.php';
$prdt = new App\Order('Civic', 'Honda', 'Classic');
var_dump($prdt);
解决方案
您为Order
班级设置了错误的命名空间。
替换namespace App;
为namespace App\Model;
推荐阅读
- kubernetes - HDFS 名称节点未在 Kubernetes 上正确显示数据节点列表
- amazon-web-services - 创建 eks 集群时 terraform 上的 ARN 错误无效
- python - 一种在列表(数组)中拆分特定项目的优雅方法?
- azure - 使用 Microsoft Blob 存储静态网站和自定义域的 CDN;一个人如何使用非www?
- docker - skaffold 不会在 minikube 中重新加载 golang 代码
- swift - 将颜色设置为 UIColor.clear 和 nil 之间有实际区别吗?- 斯威夫特
- flutter - UI中面临的问题[颤振]
- python - Python Matplotlib:for循环中的savefig图
- eclipse - 如何更改配置文件以获取正确的 java 位置以运行 scala ide - “返回的退出代码 1”
- python - 如何在本地 Jupyter Notebook 中进行离线作业?