作曲家自动加载没有正确加载文件
composer autoload doesn't load the file properly
我在自动加载文件时遇到问题,我试图找到一些解决方案但没有成功。这是我的文件结构:
my-site
- src
- - app
- - - core
- - - - App.php
- vendor
index.php
composer.json
这是我的 composer.json
"autoload": {
"psr-4": {
"App\":"src"
}
}
这是我的 App.php 文件:
namespace App\Core;
class App {}
现在,如果我尝试(进入 index.php)
require_once __DIR__ . '/vendor/autoload.php';
use App\Core\App;
var_dump( class_exists('App') );
我哪里错了?
谢谢。
我发现了我的问题,我的问题是转储自动加载,我这样试过:
composer dumpautoload -o
现在可以用了,谢谢大家!
假设您的 App.php 根据您的目录结构具有以下命名空间
<?php
namespace App\Core;
class App {
....
}
然后
"autoload": {
"psr-4": {
"App\":"src"
}
}
基本上是说包 App 从 src 文件夹的根目录开始。
my-site
- src
- - app
- - - core
- - - - App.php
- vendor
composer.json
index.php (the file that is doing the autoload if not at this level you need to adjust the file path for loading)
我发现了我的问题,我的问题是转储自动加载,我这样试过:
composer dumpautoload -o
现在可以用了,谢谢大家!
我在自动加载文件时遇到问题,我试图找到一些解决方案但没有成功。这是我的文件结构:
my-site
- src
- - app
- - - core
- - - - App.php
- vendor
index.php
composer.json
这是我的 composer.json
"autoload": {
"psr-4": {
"App\":"src"
}
}
这是我的 App.php 文件:
namespace App\Core;
class App {}
现在,如果我尝试(进入 index.php)
require_once __DIR__ . '/vendor/autoload.php';
use App\Core\App;
var_dump( class_exists('App') );
我哪里错了?
谢谢。
我发现了我的问题,我的问题是转储自动加载,我这样试过:
composer dumpautoload -o
现在可以用了,谢谢大家!
假设您的 App.php 根据您的目录结构具有以下命名空间
<?php
namespace App\Core;
class App {
....
}
然后
"autoload": {
"psr-4": {
"App\":"src"
}
}
基本上是说包 App 从 src 文件夹的根目录开始。
my-site
- src
- - app
- - - core
- - - - App.php
- vendor
composer.json
index.php (the file that is doing the autoload if not at this level you need to adjust the file path for loading)
我发现了我的问题,我的问题是转储自动加载,我这样试过:
composer dumpautoload -o
现在可以用了,谢谢大家!