拉拉威尔如何在不包括阶级的情况下扩展阶级


how laravel extends class without including them

在开始使用Laravel后,我在php中遇到了名为"namespace"的主题。在尝试理解名称空间时,我发现要在名称空间下扩展类,我需要在当前页面中包含该类。如下所示:

目录'。。''tear''teacher.php'

    namespace Teacher;
    class Teacher{
       public $headTeacher='mr X';
   }

要扩展calss,我需要包括该页面,以及使用命名空间

目录'。。''studnet''student.php'

use 'Teacher'Teacher;  //use the namespace

include('../teacher/Teacher.php'); // include the page
   class mathTeacher extends Teacher{
    public function headTeacherName(){
       echo $this->headTeacher;
    }
   }
  $student=new mathTeacher();
  $student->headTeacherName();

我想知道Laravel是如何只使用名称空间来包含类的。就像我创建了一个名为"userController"的控制器。页面结构为

namespace App'Http'Controllers;  
class userController extends Controller{
}

他们从未包含php页面,该页面包含"控制器"类。但他们能够以某种方式扩展它。此外,我可以通过使用use Viewuse Auth命令来使用"View" ,"Auth"。它是如何完成的?如何使用我提供的代码实现相同的功能?提前谢谢。

Laravel使用composer.php自动加载类。自动加载目录中的所有类都将被预加载。因此,您可以只使用名称空间并在应用程序中的任何位置消费。

了解有关composer的更多信息,composer配置可以在composer.json上的应用程序的根路径中找到