すべてのソースがこのように含まれていることを達成する必要があります
$instance = new \d1\d2\d3\app\MyClass();
d1\d2\d3\ はルート ディレクトリを指します。
https://getcomposer.org/doc/04-schema.md#psr-4 と http://www.php-fig.org/psr/psr-4/の基本を読みました 。https://laracasts.com/lessons/psr-4-autoloadingの例も機能します。
私の問題は次のとおりです。以下のコードを自分のニーズに合わせて少し変更するとすぐに、クラスが見つかりません。(はい、composer.json の変更後にコマンドを発行しcomposer update
ます。はい、自己更新を使用してコンポーザーを更新しました)。
したがって、これは機能します:
composer.json
"autoload": {
"psr-4": {
"Laracasts\\": "app/Laracasts"
}
}
index.php
require_once 'vendor/autoload.php';
// According to https://laracasts.com/lessons/psr-4-autoloading
$test = new \Laracasts\Repositories\BlogRepository();
$test->hello();
しかし、これはしません:
composer.json
"autoload": {
"psr-4": {
"d1\\": "app/Laracasts"
}
}
index.php
require_once 'vendor/autoload.php';
// According to https://laracasts.com/lessons/psr-4-autoloading
$test = new \d1\Repositories\BlogRepository();
$test->hello();
私は何を間違っていますか?
IIS 8 で php 5.3.28 を使用しています。