Laravel/Composer:使用非复合名称的use语句 [英] Laravel/Composer: The use statement with non-compound name

查看:139
本文介绍了Laravel/Composer:使用非复合名称的use语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的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中有一个引用CustomerLinksuse语句:

And I have a use statement in my ExtendedUserController that references CustomerLinks:

<?php

...
use CustomerLinks;
...

class ExtendedUserController extends UserController {

据我了解,由于composer文件中的autoload属性在类映射中具有app/model,这意味着我应该能够使用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:使用非复合名称的use语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆