问题描述:

I am trying the Slim framework as the basis for a REST api and have run into the following problem when I try to access it:

Missing argument 2 for {closure}()

I have googled it and none of the suggestions seemed to apply. This is the entire application:

require("vendor/autoload.php");

use Slim\Slim as Slim;

\Slim\Slim::registerAutoloader();

include("validate.php");

$app= new Slim();

//

// Route: GET /test/ID

//

$app->get("/test/:id",function($request,$response,$id) { <--- ERROR LINE

$status=accessAllowed("id",$request,$response);

log_info("Status: $status\n");

});

$app->run();

I'm just learning Slim and I'm assuming this is just a newbie problem. Any guidance would be appreciated.

I'm using version 3 of Slim (newest).

网友答案:

You are definitely not using slim 3 because

  1. Slim 3 no longer has the registerAutoloader(); function, and
  2. The class name changed from Slim() to App(), and
  3. The proper way to grab a parameter in Slim 3 is {id}, not :id

What you need is the proper callback signature.

$app->get("/test/:id",function($id) use ($app) {  <--- ERROR LINE
    $status=accessAllowed("id",$app->request,$app->response);
    print "Status: $status\n";
});
相关阅读:
Top