Laravel/Composer:使用非复合名称的use语句


Laravel/Composer: The use statement with non-compound name

在我的laravel项目中,我创建了一个名为CustomerLinks的模型。模型位于app/models文件夹中。我的编写器文件有一个自动加载:

"autoload": {
    "classmap": [
        ...
        "app/models",
        ...
    ],
    ...
},

我有一个use语句在我的ExtendedUserController引用CustomerLinks:

<?php
...
use CustomerLinks;
...
class ExtendedUserController extends UserController {

这是我的理解,因为自动加载属性在编译器文件有app/模型在类映射这意味着我应该能够使用use CustomerLinks没有名称空间前缀。

这工作,但任何时候我改变我的extendedusercontroller和重新加载我的浏览器我得到错误:

The use statement with non-compound name 'CustomerLinks' has no effect

错误指向use CustomerLinks行扩展用户控制器。

当我执行composer dump-autoload时一切正常,但是当我必须遵循模式

时,它变得非常令人恼火

进行更改->转储自动加载->刷新浏览器->重复

是否有处理错误的方法?

如果您不在命名空间内(即您在根命名空间中),并且您想要使用的类也不在命名空间中(即也在根命名空间中),那么使用use是没有意义的,因为没有它代码将工作相同。这句话没有导入任何东西。

Composer与此无关,也没有任何其他自动加载。这是PHP的工作原理