找不到$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';
});
因此,$router
在web.php
文件中作为全局属性提供。