Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

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

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?

question from:https://stackoverflow.com/questions/32668186/slim-3-how-to-get-all-get-put-post-variables

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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'];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...