Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

slim

psr-7

slim-3

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

Slim 2,

$allGetVars = $app->request->get(); $allPutVars = $app->request->put(); $allPostVars = $app->request->post(); 

How can I do that in Slim 3?

And, for example, http://example.com/books/1?title=hello&content=world

How can I get the params in title and content in Slim 3 now?

Slim 2,

$title = $app->request->get('title'); $content = $app->request->get('content'); 

How can I do that in Slim 3?

like image 642
Run Avatar asked Sep 19 '15 12:09

Run


Video Answer


1 Answers

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']; 
like image 178
Davide Pastore Avatar answered Sep 30 '22 02:09

Davide Pastore