New Lumen 5.5 Project' Undefined variable:app'

时间:2017-09-08 20:31:23

标签: 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->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
});

根据文件https://lumen.laravel.com/docs/5.5/routing,这应该有效。我正在关注https://paulund.co.uk/creating-a-rest-api-with-lumen发现的教程我知道5.5几天前刚出来,所以可能没有人知道答案,但任何帮助都会受到赞赏。

2 个答案:

答案 0 :(得分:7)

似乎有一些无证的变化。您需要将$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
});

答案 1 :(得分:2)

正如misbachul munir所述,$app已更改为$router

但您必须至少更新bootstrap/app.phproutes/web.php中的参考文献。检查文件,您不必进行简单的搜索和替换,因为它只需要在某些地方进行更改。

例如,$app->version()现在是$router->app->version()

编辑:它位于"更新引导程序文件"

下的文档https://lumen.laravel.com/docs/5.5/upgrade
相关问题