Slim 3 - how to get all get/ put/ post variables?

后端 未结 4 1496
Happy的楠姐
Happy的楠姐 2020-12-23 09:38

How I can get all get/ put/ post variables like in Slim 2 for Slim 3?

Slim 2,

$allGetVars = $app->request->get()         


        
相关标签:
4条回答
  • 2020-12-23 10:12

    Get all get/put/post parameters:

    //GET
    $allGetVars = $request->getQueryParams();
    foreach($allGetVars as $key => $param){
       //GET parameters list
    }
    
    //POST or PUT
    $allPostPutVars = $request->getParsedBody();
    foreach($allPostPutVars as $key => $param){
       //POST or PUT parameters list
    }
    

    Single parameters value:

    //Single GET parameter
    $getParam = $allGetVars['title'];
    
    //Single POST/PUT parameter
    $postParam = $allPostPutVars['postParam'];
    
    0 讨论(0)
  • 2020-12-23 10:20

    To Get all request params:

    $request->getParams() 
    
    0 讨论(0)
  • 2020-12-23 10:21

    You can use the map() method to combine get, post & put into a single route.

    $app->map(['GET', 'POST', 'PUT'], function(Request $request, Response $response, array $args)) { }
    

    The first argument is an array of the HTTP methods that you want to match. The second parameter is the function that handles the request; pass a request, response and an array of arguments.

    0 讨论(0)
  • 2020-12-23 10:24

    Request Uri: getQueryParams()

    Request Body: getBody()/getParsedBody()

    It's not exactly what you are looking for but it comes pretty close.

    0 讨论(0)
提交回复
热议问题