[英]Composer PSR-4 autoloading completely ignored
我有 composer.json 文件:
{
"name": "marko/art-empire",
"description": "Social network",
"type": "project",
"authors": [
{
"name": "Marko Ilic",
"email": "markowebdeveloper@gmail.com"
}
],
"require": {},
"autoload": {
"psr-4": {
"Songs\\": "songs/"
}
}
}
autoload_psr4.php 文件:
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Songs\\' => array($baseDir . '/songs'),
);
歌曲文件夾中的RandomSong.php文件(在根目錄下):
namespace Song;
class RandomSong
{
public function songName()
{
return 'Random Song';
}
}
test.php 文件:
require 'vendor/autoload.php';
use Songs\RandomSong;
$randomSong = new RandomSong();
echo $randomSong->songName();
如您所見,我正在嘗試自動加載 RandomSong 類,但我不斷收到:
Fatal error: Uncaught Error: Class 'Songs\RandomSong' not found in test.php
請幫忙,謝謝。
您的命名空間稱為Song
,但您將其稱為Songs
您的RandomSong
使用Song
命名空間,而您的加載程序用於Songs
命名空間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.