【问题标题】:New Lumen 5.5 Project 'Undefined variable: app'新 Lumen 5.5 项目“未定义变量:app”
【发布时间】:2018-02-17 19:58:06
【问题描述】:

我是 Lumen 的新手,刚刚尝试创建一个应用程序。我在 Application->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
});

根据文件https://lumen.laravel.com/docs/5.5/routing,这应该可以工作。我正在关注https://paulund.co.uk/creating-a-rest-api-with-lumen 上的教程,我知道 5.5 几天前刚刚发布,所以可能还没有人知道答案,但我们将不胜感激。

【问题讨论】:

    标签: php lumen


    【解决方案1】:

    似乎有一些未记录的更改。您需要将$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
    });
    

    【讨论】:

    • 解决了我的问题。谢谢!
    【解决方案2】:

    正如misbachul munir所说,$app改为$router

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

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

    编辑:它位于“更新引导文件”下的文档 https://lumen.laravel.com/docs/5.5/upgrade

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-11
      • 1970-01-01
      • 2020-02-26
      • 2018-07-11
      • 1970-01-01
      • 2020-09-29
      • 2017-10-16
      • 1970-01-01
      相关资源
      最近更新 更多