简体   繁体   English

关键字'use'如何在php(laravel)中工作

[英]how does keyword 'use ' works in php (laravel)

I don't understand how does use keyword works in laravel framework我不明白在 Laravel 框架中 use 关键字是如何工作的

I create a controller PostsManagerController.php我创建了一个控制器PostsManagerController.php

this controller has a namespace App\\Http\\Controllers;这个控制器有一个namespace App\\Http\\Controllers;

until here everything is fine the problem is in routes/web.php直到这里一切正常,问题出在routes/web.php

i find this two lines我发现这两行

use App\Http\Controllers\PostsManagerController;

use Illuminate\Support\Facades\Route;

my question is how routes/web.php know the PostsManagerController class and Route class without import any of them我的问题是routes/web.php如何知道 PostsManagerController 类和 Route 类而不导入它们

as I know if we want use or deal with a class in other file first we need to import it我知道如果我们想首先使用或处理其他文件中的类,我们需要导入它

in Laravel app there is a public folder .在 Laravel 应用程序中有一个public文件夹。 there is a file name index.php ..which require..有一个文件名index.php .. 需要..

require __DIR__.'/../vendor/autoload.php';

Note index.php is the entry point of Laravel application注意index.php是 Laravel 应用的入口点

in vendor folder.. if you go there there is a file autoload.phpvendor文件夹中.. 如果你去那里有一个文件autoload.php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInita990d9507b876ea05d2300077581f677::getLoader();

autoload.php file autoload all classes file... autoload.php文件自动加载所有类文件...

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

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