我在名稱空間中出現以下錯誤。我搜索並試圖實現所有我找到的解決方案,但我無法解決它。使用名稱空間時出錯
錯誤:
Fatal error: Uncaught Error: Class 'App\Models\Site\User' not found in /Applications/MAMP/htdocs/php-sem-medo/ORM/index.php on line 4
的index.php
<?php
require_once "config.php";
use App\Models\Site\User as User;
$user = new User;
dump($user -> all());
?>
Model.php
<?php
namespace App\Models{
class Model extends \ActiveRecord\Model { };
}
?>
user.php的
<?php
namespace App\Models\Site{
use App\Models\Model;
class User extends Model {
static $table_name = 'users';
}
}
?>
composer.json
{
"require": {
"php-activerecord/php-activerecord": "^1.1"
},
"autoload":{
"psr-4":{
"App\\":"App"
}
}
}
的config.php
<?php
require_once 'vendor/autoload.php';
require_once 'connection.php';
?>
目錄結構
php-sem-medo -> ORM -> App -> Models-> Model.php
|-> APP -> Models -> Site -> User.php
|-> vendor -> composer
|-> vendor -> php-activerecord
|-> vendor -> autoload.php
|-> composer.json
|-> composer.lock
|-> config.php
|-> connection.php
|-> index.php
對不起,你正在寫,我剛剛添加。再次跟隨它。 php-sem-medo - > ORM - > App - > Models-> Model.php | - > APP - > Models - > Site - > User.php | - > vendor - > composer | - > vendor - > PHP-了activerecord | - >供應商 - > autoload.php | - > composer.json | - > composer.lock | - >的config.php | - > connection.php | - >的index.php –