流明'web.php'中定义'$router'变量在哪里?



找不到$router变量在流明web.php中定义的位置。web.php的内容就是这样,不清楚$router变量是如何定义的:

<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/
$router->get('/', function () use ($router) {
return $router->app->version();
});

如您所见,没有预先定义$router变量。它是从另一个文件加载到这里的吗?

这是神奇的:)如果您打开bootstrap/app.php这是引导整个应用程序并加载路由的内容,您将看到以下代码:

$app->router->group([
'namespace' => 'AppHttpControllers',
], function ($router) {
require __DIR__.'/../routes/web.php';
});

因此,$routerweb.php文件中作为全局属性提供。

最新更新