I'm creating an app to use autoload in composer.json to load my class files. I was getting
Fatal error: Uncaught Error: Class 'Order' not found in C:\apache\htdocs\inventory_manager\app\public\index.php:17
I checked the path of the $vendorDir folder relative to my $baseDir in the vendor/composer/autoload_psr4.php and its correct. I've checked through threads with similar issues but still. Thanks in advance
This is my composer.json file
{
"name": "inventory manager",
"description": "Inventory Management System",
"require": {
"phpmailer/phpmailer": "~6.0"
},
"autoload": {
"psr-4": {
"App\\": "app"
}
}
}
This is my folder Structure
|---inventory_manager
|---app
|---Model
|---DatabaseObject.php
|---Order.php
|---Product.php
|---public
|---assets
|---css
|---index.php
|---vendor
|---composer.json
Order.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}";
}
}
index.php
<?php
require '../../vendor/autoload.php';
$prdt = new App\Order('Civic', 'Honda', 'Classic');
var_dump($prdt);
order
class needs to be in the\app\Model\Order
namespace. – Nicholas Summers