我在嘗試在Lumen中使用自定義名稱空間類時遇到了問題,Laravel提供了微觀框架。嘗試實例化類時出現Class not found
錯誤。Laravel/Lumen自定義類未找到
相對目錄:
|--- app
| |---Classes
| | |--- GetImages.php < My custom, namespaced class
|--- Http
|--- |--- routes.php < Using the class here works
| |--- Processors
| | |--- get.php < Using the class here does not work, generates the error (listed below)
的GetImages.php文件,減少爲了簡潔:
namespace App\Classes;
class GetImages
{
public $name = 'Class instantiated';
}
的get.php文件,其中的錯誤發生:
use App\Classes\GetImages;
$n = new GetImages;
return $n->name;
如果我做一個0123主頁像$.get('http://www.example.com/app/Http/Processors/get.php')
內請求我收到以下錯誤:
Fatal error: Class 'App\Classes\GetImages' not found in http://www.example.com/app/Http/Processors/get.php on line 5.
然而,如上所述,如果我實例化routes.php
文件中這一類,它工作正常。
的composer.json
的自動加載部分:
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/"
],
"files": [
"app/Http/helpers.php"
]
}
我覺得這是一個自動加載的問題,但我已經做了composer dumpautoload -o
,composer update
,其次PSR-4
標準,沒有任何變化。任何想法我失蹤?
您未能向我們展示'composer.json'的自動加載部分。 – Sven
@Sven我已經更新,包括現在。你覺得有一個更合適的方式來處理這個問題,而不是下面提供的答案嗎? – camelCase