Class 'App\Http\Database\Model' 未找到

Class 'App\Http\Database\Model' not found

我正在使用 composer 自动加载 classes,但由于某些原因 class Model 在我的 Controller

中找不到

Controller.php

namespace App\Http\Controllers;

use App\Http\Database\Model;

class Controller extends Model
{

    public function insert($query){

        $results = $this->model->query($query)->fetchAll();

        return $results;
    }
}

现在我的 Model 文件中有一个到 MySQL

的简单 PDO 连接

Model.php

namespace app\Http\Database;

class Model extends Database
{
    public $model;

    function __construct()
    {
        try {
            $this->model = new \PDO("mysql:host=".Database::DB_HOST."; dbname=".Database::DB_DATABASE."", "".Database::DB_USER."", "".Database::DB_PASS."", array(\PDO::ATTR_PERSISTENT => false));
            $this->model->exec("SET CHARACTER SET utf8");
            return $this->model;

        } catch (PDOException $e) {
            echo "Cannot connect to the Database";
            die();
        }
    }
}

这是我 index.php

上的内容

index.php

namespace App\Http\Controllers;

error_reporting(E_ALL);
ini_set("display_errors", 1);

require_once __DIR__ . '/../vendor/autoload.php';

$controller = new Controller();

$query = 'SELECT * FROM pages WHERE id = 1';

print_r($controller->insert($query));

autoload.php

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    'App\Http\Controllers\Controller' => $baseDir . '/app/Http/Controllers/Controller.php',
    'App\Http\Controllers\IndexController' => $baseDir . '/app/Http/Controllers/IndexController.php',
    'App\Http\Database\Database' => $baseDir . '/app/Http/Database/Database.php',
    'app\Http\Database\Model' => $baseDir . '/app/Http/Database/Model.php',
);

我在这里错过了什么?你能给我指出正确的方向吗?

能否请您检查模型中的命名空间 Class。请将其重命名为 App\Http\Database

或者,修复导入:

use app\Http\Database\Model;

但是,您可能想要按照已经建议的那样修复命名空间。