php为命名函数传递参数

问题描述 投票:0回答:2

我正在使用PHP slim框架版本2.在他们的文档中,他们没有指定如何传递参数来调用如何在函数中接收参数。

$app->get('/books/{id}', 'getBook')

function getBook($id){
var_dump($id);
    die('there');

}

但它给了我一个错误,或者找不到或者

All Route middleware must be callable
php rest slim
2个回答
0
投票

@ owaishanif786我不知道这种方式($ app-> get('/ books / {id}','getBook'))你在你的问题中使用但如果我想在苗条框架2中调用一个函数然后我就像下面这样做,请检查:

$app->get('/total', function() use($app){
        test(2);
    });

    function test($id){
        echo "yes you were right $id";
    }

现在只需调用/ total api你的函数test(),参数$ id将调用


0
投票

截至Slim v3

$app->get('/books/{id}', function ($request, $response, $args) {
    // $args['id']
});
© www.soinside.com 2019 - 2024. All rights reserved.