问题描述
我是laravel的新手,在我的应用程序中遇到了psr-4自动加载的问题.
I'm fairly new to laravel and have encountered a problem with the psr-4 autoloading in my application.
我的文件夹结构:
-app
-config
-controllers
-UsersController
-Mynamespace
-User.php
我的composer.json文件:
My composer.json file:
"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 {
...
我的供应商/composer/autoload-psr4.php:
My vendor/composer/autoload-psr4.php:
...
return array(
'Monolog\\' => array($vendorDir . '/monolog/monolog/src/Monolog'),
'Mynamespace\\' => array($baseDir . '/app/Mynamespace'),
);
将我的config/auth.php更改为:
Changed my config/auth.php to:
'model' => 'Mynamespace\User',
我不断收到ReflectionException类用户不存在错误.请帮忙!
I keep getting a ReflectionException Class User does not exist error. Please help!
推荐答案
您反映了异常
抱怨无法找到名为 User
的类.我没有在上面的代码中的任何地方看到名为 User
的类.我看到一个名为 Mynamespace \ User
的类,但是没有看到一个名为user的全局类.
is complaining about not being able to find a class named User
. I don't see a class named User
defined anywhere in the above code. I see a class named Mynamespace\User
, but I don't see a global class named user.
知道您在其中看到此异常的上下文会有所帮助,但是我的猜测是告诉Laravel实例化全局 User
对象(依赖项注入类型提示?通过实例化对象)app()-> make
?直接实例化一个对象?).没有这种背景,任何人都不可能为您追踪到这一点.
Knowing the context that you're seeing this exception in would help, but my guess is something told Laravel to instantiate a global User
object (dependency injected type hints? Instantiating an object through app()->make
? Directly Instantiating an object?). Without that context it's not likely anyone will be able to track this down for you.
这篇关于ReflectionException类不存在psr-4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!