duanqiangwu9332 2017-01-02 11: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 11: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.

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

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部