I'm new to PHP and I'm following an online course (for this reason I'm not using autoloading or any other way to load classes).
My problem is that my controller class (in which I'm using "use") cannot see my model class (in which I've declared the namespace).
The error is:
Fatal error: Uncaught Error: Class 'App\Models\Post' not found in C:\xampp_php729\htdocs\Freeblog\App\Controllers\postController.php on line 20
Here is my code:
PostController.php
namespace App\Controllers;
use App\Models\Post;
class PostController {
protected $layout = __DIR__ . '/../../Layout/index.template.php';
protected $conn;
public $content;
public $posts;
protected $myPost;
public function __construct(\PDO $conn) {
$this->conn = $conn;
try {
$this->myPost = new Post($conn);
} catch (Exception $e) {
die($e->getMessage());
}
$this->content = $this->process();
}
....
}
Post.php:
namespace App\Models;
use \PDO;
class Post {
protected $conn;
public function __construct(PDO $conn){
$this->conn = $conn;
}
...
}
This is the project structure:
