[英]New Lumen 5.5 Project 'Undefined variable: app'
I am new to Lumen and just tried to create an app. 我是Lumen的新手,只是尝试创建一个应用程序。 I am getting an error that states at Application->Laravel\\Lumen\\Concerns{closure}(8, 'Undefined variable: app', '/Users/test/Sites/books/routes/web.php', 14, array('router' => object(Router))) when I try to use this bit of code:
我在应用程序-> Laravel \\ Lumen \\ Concerns {closure}(8,'Undefined variable:app','/Users/test/Sites/books/routes/web.php',14,array(当我尝试使用以下代码时,'router'=> object(Router))):
$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
});
According to the documents https://lumen.laravel.com/docs/5.5/routing this should work. 根据文档https://lumen.laravel.com/docs/5.5/routing,这应该可以工作。 I am following a tutorial found at https://paulund.co.uk/creating-a-rest-api-with-lumen I know that 5.5 just came out a few days ago, so there might not be anyone that knows the answer yet, but any help would be appreciated.
我正在跟踪在https://paulund.co.uk/creating-a-rest-api-with-lumen上找到的教程,我知道5.5几天前才问世,所以可能没有人知道答案但是,任何帮助将不胜感激。
There seems some undocumented change. 似乎有一些未记录的更改。 You need to change
$app
into $router
as follow: 您需要将
$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
});
As misbachul munir said, $app
changed to $router
. 正如misbachul munir所说,
$app
更改为$router
。
But you have to, at least, update your references in bootstrap/app.php and routes/web.php . 但是,您至少必须在bootstrap / app.php和route / web.php中更新您的引用。 Check the files, you do not have to do a simple search-and-replace because it only needs to change in some places.
检查文件,您不必进行简单的搜索和替换,因为只需要在某些位置进行更改即可。
For example, $app->version()
is now $router->app->version()
例如,
$app->version()
现在是$router->app->version()
EDIT: It is in the docs https://lumen.laravel.com/docs/5.5/upgrade under "Updating The Bootstrap File" 编辑:它在docs https://lumen.laravel.com/docs/5.5/upgrade中的 “更新引导文件”下
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.