2

是否可以在中间件函数中获取请求方法(GET、POST、PUT、...)?

$myMiddleware = function (Request $request) {
    // This is what I want to achieve
    switch ($request->request->get('method') { 
        case 'GET':
            // ...
        break;
    }
}

$app = new Application();
$app->before($myMiddleware);
4

1 回答 1

6

感谢普特万德。很简单:

$request->getMethod();
于 2013-08-11T20:35:35.730 回答