简体   繁体   English

Laravel&Namespacing

[英]Laravel & Namespacing

This is probably nitpicky, but I was wondering how the namespace for the Laravel 4.2 "Route" works (using the resource function). 这可能是挑剔的,但我想知道Laravel 4.2“Route”的命名空间是如何工作的(使用资源函数)。

So... in all the documentation ( http://laravel.com/docs/4.2/controllers#resource-controllers ), you see this: 所以...在所有文档( http://laravel.com/docs/4.2/controllers#resource-controllers )中,您会看到:

Route::resource('photo', 'PhotoController');

However, when I go to the "Route" documentation ( http://laravel.com/api/4.2/Illuminate/Routing/Route.html ) you can see that the function "resource", doesn't exist there. 但是,当我转到“路线”文档( http://laravel.com/api/4.2/Illuminate/Routing/Route.html )时,您可以看到功能“资源”在那里不存在。 Instead, it exists under "Route r " ( http://laravel.com/api/4.2/Illuminate/Routing/Router.html ). 相反,它存在于“Route r ”下( http://laravel.com/api/4.2/Illuminate/Routing/Router.html )。

How do I use the PHP "use" statements to specify that I'm using the resource function? 如何使用PHP“use”语句指定我正在使用资源函数? The example itself is accurate and works when I call (in that it shows all the routes that I expect): 示例本身是准确的,并在我调用时工作(因为它显示了我期望的所有路由):

php artisan routes

How does Laravel make the Route vs. Router namespace work? Laravel如何使Route vs. Router命名空间工作?

Laravel heavily uses Facades . Laravel大量使用Facades They're basically classes that allow static access ( Route::resource() ) to methods that are not static at all. 它们基本上是允许静态访问( Route::resource() )到完全不是静态的方法的类。 In the background it makes a new instance of the Router class and then calls the method resource() . 在后台,它创建了一个Router类的新实例,然后调用方法resource() You can find more information about it in the docs 您可以在文档中找到有关它的更多信息

If you are looking for proper auto-completion and other IDE features that rely on resolving the class, try the laravel ide helper 如果您正在寻找适当的自动完成和其他依赖于解析类的IDE功能,请尝试使用laravel ide帮助程序

The thing is that Route here is not class but it's a facade . 问题是这里的Route不是阶级,而是外观 If you look at Facade class reference you will see that Route facade is using Illuminate\\Routing\\Router router so it's the class you want 如果您查看Facade类引用,您将看到Route facade正在使用Illuminate\\Routing\\Router路由器,因此它是您想要的类

The Route in app/routes.php is just another of Laravel's various facades and contains rules processed by the Laravel Routing Engine to produce the actual routes that will be used in your application. app/routes.php routes.php中的 Route只是Laravel各种外观中的另一个,包含由Laravel路由引擎处理的规则 ,用于生成将在您的应用程序中使用的实际路由

To get a better understanding, I'd suggest checking out this short guide to Laravel Architecture to understand how requests are received and processed in the framework, as well as Rebuilding Laravel which explains how the various Laravel components are built starting from the first file that is processed. 为了更好地理解,我建议查看这个Laravel Architecture的简短指南,以了解如何在框架中接收和处理请求,以及重建Laravel ,它解释了如何从第一个文件开始构建各种Laravel组件已处理。

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

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