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 ?

图片转代码服务由CSDN问答提供 功能建议

通过考虑此文件结构

  |  -  src / 
 |  - 供应商
 |  - 型号
 |  - 图书馆
 |  -  ... 
 |  -  composer.json 
   
 
 

如何在“模型”和“模型”中自动加载类? 'libraries'目录?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

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条)

相关推荐 更多相似问题