简体   繁体   English

Laravel BaseController vs \\ BaseController

[英]Laravel BaseController vs \BaseController

The default HomeController class is defined using 使用默认的HomeController类定义

class HomeController extends BaseController {

However, when a resource controller is created via artisan , the class extends \\BaseController instead of BaseController . 但是,当通过artisan创建资源控制器时,该类扩展了\\BaseController而不是BaseController Why is this, and what is the difference? 这是为什么,有什么区别?

class TestResourceController extends \BaseController {

There is no difference (in a default installation). 没有区别(在默认安装中)。 The \\ simply tells PHP to use the root namespace instead of any other class with the same name but on a different namespace. \\只是告诉PHP使用根命名空间而不是任何其他具有相同名称但在不同命名空间的类。 If you were to create your own class called BaseController, PHP would not know which class to use unless it were explicity defined by the namespace, ie MyNamespace\\BaseController . 如果您要创建自己的类BaseController,PHP将不知道要使用哪个类,除非它是由命名空间明确定义的,即MyNamespace\\BaseController

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM