duanfei8149 2017-05-05 11:02
浏览 326
已采纳

如何使用composer autoloader自动加载我的类?

By considering this files structure

| -- src /
        | -- vendor
        | -- models
        | -- libraries
        | -- ...
        | -- composer.json

How can I autoload classes located in 'models' & 'libraries' directories ?

  • 写回答

2条回答 默认 最新

  • dongtao1262 2017-05-05 11:21
    关注

    You can add your own autoloader rules into the composer.json file in your project - this adds your own rules to the vendor/autoload.php file so that your own classes will load as well as the ones in the vendor/ directory. There's more information in the docs here: https://getcomposer.org/doc/04-schema.md#autoload. Take a look at the PSR-0 section to load classes from your two directories.

    Try something like:

    {
        "autoload": {
            "psr-0": { "": ["models/", "libraries"] }
        }
    }
    

    If your classes are namespaced, then specify the namespaces as this will stop composer from looking for all classes in those directories.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失
  • ¥15 springboot+vue 集成keycloak sso到阿里云
  • ¥15 win7系统进入桌面过一秒后突然黑屏
  • ¥30 backtrader对于期货交易的现金和资产计算的问题
  • ¥15 求C# .net4.8小报表工具
  • ¥15 安装虚拟机时出现问题
  • ¥15 Selenium+docker Chrome不能运行
  • ¥15 mac电脑,安装charles后无法正常抓包
  • ¥18 visio打开文件一直显示文件未找到