簡體   English   中英

新的Lumen 5.5項目“未定義變量:應用程序”

[英]New Lumen 5.5 Project 'Undefined variable: app'

我是Lumen的新手,只是嘗試創建一個應用程序。 我在應用程序-> 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幾天前才問世,所以可能沒有人知道答案但是,任何幫助將不勝感激。

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

正如misbachul munir所說, $app更改為$router

但是,您至少必須在bootstrap / app.phproute / web.php中更新您的引用。 檢查文件,您不必進行簡單的搜索和替換,因為只需要在某些位置進行更改即可。

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

編輯:它在docs https://lumen.laravel.com/docs/5.5/upgrade中的 “更新引導文件”下

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM