Php 新Lumen 5.5项目';未定义变量:app';
我是Lumen的新手,刚刚尝试创建一个应用程序。当我尝试使用这段代码时,我在Application->Laravel\Lumen\Concerns{closure}(8,'未定义变量:app','/Users/test/Sites/books/routes/web.php',14,array('router'=>object(router)))处遇到一个错误:Php 新Lumen 5.5项目';未定义变量:app';,php,lumen,Php,Lumen,我是Lumen的新手,刚刚尝试创建一个应用程序。当我尝试使用这段代码时,我在Application->Laravel\Lumen\Concerns{closure}(8,'未定义变量:app','/Users/test/Sites/books/routes/web.php',14,array('router'=>object(router)))处遇到一个错误: $app->group(['prefix' => 'book/'], function() use ($app) {
$app->group(['prefix' => 'book/'], function() use ($app) {
$app->get('/','BooksController@index'); //get all the routes
$app->post('/','BooksController@store'); //store single route
$app->get('/{id}/', 'BooksController@show'); //get single route
$app->put('/{id}/','BooksController@update'); //update single route
$app->delete('/{id}/','BooksController@destroy'); //delete single route
});
根据文件,这应该是可行的。我正在关注一个在我知道5.5几天前刚刚发布的教程,所以可能还没有人知道答案,但是任何帮助都将不胜感激 似乎有一些未记录的变化。您需要将
$app
更改为$router
,如下所示:
$router->group(['prefix' => 'book/'], function() use ($router) {
$router->get('/','BooksController@index'); //get all the routes
$router->post('/','BooksController@store'); //store single route
$router->get('/{id}/', 'BooksController@show'); //get single route
$router->put('/{id}/','BooksController@update'); //update single route
$router->delete('/{id}/','BooksController@destroy'); //delete single route
});
如上所述,$app
更改为$router
但你至少必须在和中更新你的引用。检查文件,您不必进行简单的搜索和替换,因为它只需要在某些地方进行更改
例如,$app->version()
现在是$router->app->version()
编辑:在文档中的“更新引导文件”下解决了我的问题。谢谢