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.

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

报告相同问题?

悬赏问题

  • ¥30 基于信创PC发布的QT应用如何跨用户启动后输入中文
  • ¥20 非root手机,如何精准控制手机流量消耗的大小,如20M
  • ¥15 远程安装一下vasp
  • ¥15 自己做的代码上传图片时,报错
  • ¥15 Lingo线性规划模型怎么搭建
  • ¥15 关于#python#的问题,请各位专家解答!区间型正向化
  • ¥15 unity从3D升级到urp管线,打包ab包后,材质全部变紫色
  • ¥50 comsol温度场仿真无法模拟微米级激光光斑
  • ¥15 上传图片时提交的存储类型
  • ¥15 VB.NET如何绘制倾斜的椭圆