dqsong2010 2012-10-03 19:16
浏览 229
已采纳

在composer中指定PSR-0命名空间的根目录

I current have the following composer.json file:

{
    "require": {
        "slim/slim": "2.*"
    },
    "autoload": {
        "psr-0": { "App": "app/" }
    }
}

I'm trying to instantiate a class in the app folder, but the autoloader is looking for:

/var/www/framework/app//App/App.php

Obviously the second parameter is the folder containing the namespace rather than the root of the namespace. How can I make it load:

/var/www/framework/app/App.php

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongshan4518 2012-10-03 19:45
    关注

    The easiest solution is to rename the folder from app to App and set

    "psr-0": { "App": "." }
    

    I guess else you need a custom autoloader. However, I recommend to follow some proven use-cases:

    src/App/App.php
    

    with

    "psr-0": { "App": "src" }
    

    Looks curious, but I must say, that I would never call a namespace or class (or even both) just App ;) It doesn't say anything and with aliasing (use MyApplication as App) there is no reason anymore to write as short identifiers as possible.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀