问题描述
在我的 laravel 项目中,我创建了一个名为 CustomerLinks
的模型.该模型位于 app/models
文件夹中.我的作曲家文件自动加载:
In my laravel project I created a model called CustomerLinks
. The model resides in the app/models
folder. My composer file has an autoload of:
"autoload": {
"classmap": [
...
"app/models",
...
],
...
},
我的 ExtendedUserController 中有一个 use
语句,它引用了 CustomerLinks
:
And I have a use
statement in my ExtendedUserController that references CustomerLinks
:
<?php
...
use CustomerLinks;
...
class ExtendedUserController extends UserController {
据我了解,由于 composer 文件中的 autoload 属性在 classmap 中有 app/models,这意味着我应该能够在没有命名空间前缀的情况下使用 use CustomerLinks
.
It's my understanding that since the autoload property in the composer file has app/models in the classmap it means I should be able to use use CustomerLinks
without a namespace prefix.
这可行,但每当我更改我的 ExtendedUserControler 并重新加载我的浏览器时,我都会收到错误消息:
This works, but any time I make a change to my ExtendedUserControler and reload my browser I get the error:
The use statement with non-compound name 'CustomerLinks' has no effect
错误指向 use CustomerLinks
行扩展用户控制器.
The error points to the use CustomerLinks
line extended user controller.
当我执行 composer dump-autoload
时,一切正常,但当我必须遵循模式时,它变得非常烦人
When I do a composer dump-autoload
everything works fine, but it becomes extremely irritating when I have to follow the pattern
进行更改 -> 转储自动加载 -> 刷新浏览器 -> 重复
make a change -> dump autoload -> refresh browser -> repeat
有没有办法处理这个错误?
Is there some way of dealing with the error?
推荐答案
如果你不在命名空间内(即你在根命名空间内),而你要使用的类也不在命名空间内(即也在根命名空间中),然后使用 use
没有意义,因为没有它,代码将同样工作.您没有使用此语句导入任何内容.
If you are not within a namespace (i.e. you are in the root namespace), and the class you want to use also is not in a namespace (i.e. also in the root namespace), then using use
makes no sense, because the code will work the same without it. You are not importing anything with this statement.
Composer 与此无关,也没有任何其他自动加载.PHP 本身就是这样工作的.
Composer has nothing to do with this, neither has any other autoloading. It's how PHP works by itself.
这篇关于Laravel/Composer:使用非复合名称的语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!