composer 实现自动加载

composer 实现自动加载

composer

1.确保引入了 vendor/autoload.php 文件

2.打开composer.json 文件,修改值:

{
    "require": {
        "swoole/ide-helper": "^4.6",
        "phpunit/phpunit": "^9.5",
        "spatie/array-to-xml": "^2.15",
        "fzaninotto/faker": "^1.9",
        "topthink/think-orm": "^2.0",
        "endroid/qr-code": "^4.0"
    },
    "autoload": {
        # 格式"命名空间开头\\": "对应的目录"
        "psr-4": {
            "app\\" : "app/",
            
            
        },
        #要自动加载的文件
        "files":[
            "PHP/helper/file.php",
            
        ]
    }
}
3.在命令行,打开在composer.json 所在目录;执行命令 composer dump-autoload即可

留下回复


Warning: is_dir(): open_basedir restriction in effect. File(/www/wwwroot/my-wordpress/index.php/2021/05/22/composer-%E5%AE%9E%E7%8E%B0%E8%87%AA%E5%8A%A8%E5%8A%A0%E8%BD%BD/) is not within the allowed path(s): (/www/wwwroot/my-wordpress/:/tmp/) in /www/wwwroot/my-wordpress/wp-content/plugins/matomo/classes/WpMatomo/AIBotTracking.php on line 175