duanqiangwu9332 2017-01-02 19:01
浏览 56
已采纳

超薄3中间件和psr-4作曲家自动加载器:找不到类

composer.json:

"autoload": {
    "psr-4": {
        "App\\": "src/"
    }
},

src/Auth/RequestMethodPathRule.php:

namespace App\Auth;
class RequestMethodPathRule implements  \Slim\Middleware\HttpBasicAuthentication\RuleInterface 
{ 
...

src/middleware.php

$app->add(new \Slim\Middleware\HttpBasicAuthentication([
    "rules" => [new App\Auth\RequestMethodPathRule(

This results in

Class 'App\Auth\RequestMethodPathRule' not found.

Including all of the code in RequestMethodPathRule.php in the file middleware.php works fine.

More strangely, along with the 500 error, the browser displays the source code of RequestMethodPathRule.php!

EDIT: Oh my, I had a shorttag on the class file (<? instead of <?php) so php treated it as text. Habits are hard to quit.

  • 写回答

1条回答 默认 最新

  • dprnr5559 2017-01-02 19:26
    关注

    More strangely, along with the 500 error, the browser displays the source code of RequestMethodPathRule.php!

    That's mean that composer correctly include the file, but no class is found because the code isn't interpret by php. In this case, since the short tags aren't a usually enabled, you just need to replace them with the <?php tag instead.

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

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码