Help us understand the problem. What is going on with this article?

Composerでautoload.phpを作成する

More than 1 year has passed since last update.

Composerでオートローダを作成する方法

ディレクトリ構成
composer.json
src/
  index.php
  bar/
    Hoge.php   ... foo\bar\Hoge クラス
composer.json
{
    "autoload": {
        "psr-4": {
            "foo\\": "src"
        }
    }
}

*composer.jsonの記述は場合によってことなります。
https://qiita.com/suin/items/b31e3c5bff15c821ccaa

コマンドラインでcomposer.jsonが置いてあるディレクトリに移動し
コマンドを実行

composer dump-autoload

vendorが生成される

composer.json
vendor/
  composer/
  autoload.php
src/
  index.php
  bar/
    Hoge.php   ... foo\bar\Hoge クラス

autoload.phpを読み込む

index.php
<?php
use foo\bar\Hoge;

require_once __DIR__.'/../vendor/autoload.php';

参考文献

Composerのautoloadの書き方早見表

PHP開発でComposerを使わないなんてありえない!基礎編

tkek321
自分用のメモくらいに使おうかなと思ってます。 マサカリ募集。
miraito-inc
システムデザインを中心に置いた開発により高品質で使いやすいシステムを提供いたします。業務システム構築、アプリ開発、コンサルティングまで幅広く手がけています。
https://miraito-inc.co.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした