【问题标题】:ReflectionException Class does not exist psr-4ReflectionException 类不存在 psr-4
【发布时间】:2015-01-12 09:37:45
【问题描述】:

我是 laravel 的新手,在我的应用程序中遇到了 psr-4 自动加载的问题。

我的文件夹结构:

-app
 -config
  -controllers
   -UsersController
  -Mynamespace
   -User.php

我的 composer.json 文件:

"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php"
    ],
    "psr-4": {
      "Mynamespace\\": "app/Mynamespace"
    }

然后我跑了:

composer dump-autoload

我的用户模型:

<?php namespace Mynamespace;

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
use Eloquent;

class User extends Eloquent implements UserInterface, RemindableInterface {
...

我的供应商/作曲家/autoload-psr4.php:

...
return array(
    'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
    'Mynamespace\\' => array($baseDir . '/app/Mynamespace'),
);

将我的 config/auth.php 更改为:

'model' => 'Mynamespace\User',

我不断收到 ReflectionException Class User does not exist 错误。请帮忙!

【问题讨论】:

  • 您是否将model 中的app/config/auth.php 更改为Mynamespace\User
  • 对'model'是的 => 'Mynamespace/User',
  • 您的用户模型存储在一个名为User.php 的文件中,对吗?我问是因为您将其称为您的 UsersController。
  • 对!对此感到抱歉。

标签: php laravel psr-4


【解决方案1】:

你反射异常

类用户不存在错误

抱怨找不到名为User 的类。我没有在上面的代码中的任何地方看到一个名为User 的类。我看到一个名为 Mynamespace\User 的类,但我没有看到一个名为 user 的全局类。

知道你看到这个异常的上下文会有所帮助,但我的猜测是告诉 Laravel 实例化一个全局 User 对象(依赖注入类型提示?通过 app()-&gt;make 实例化一个对象?直接实例化一个对象?)。如果没有该上下文,任何人都不太可能为您追踪到这一点。

【讨论】:

    猜你喜欢
    • 2014-01-24
    • 2014-05-29
    • 1970-01-01
    • 1970-01-01
    • 2014-12-11
    • 2017-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多