简体   繁体   English

如何使用PHP在苗条框架中使用request-> getBody()获取表单数据?

[英]How to get the form data using request->getBody() in slim framework using php?

I am trying the fetch the form data. 我正在尝试获取表单数据。 I dont know where the mistake is. 我不知道错误在哪里。

<html>
<head>
<title>Student</title>
</head>
<body>
<form name="std" action="insert/std_insert" method="POST">
Student id:<input type="text" name="std_id" id="std_id"><br>
Student name:<input type="text" name="std_name" id="std_name"><br>
<input type="submit" name="submit" value="submit">
</body>
</html>

This is the code for fetching 这是获取代码

<?php
error_reporting(0);
$app = new \Slim\Slim();
$body = $app->request->getBody();
echo json_encode($body);
?>

The request object is not full-filled until the app has been run. 在应用程序运行之前,请求对象尚未完全填充。 IE $app->run(); IE $ app-> run(); You are actually not using Slim correctly. 您实际上没有正确使用Slim。 docs.slimframework.com docs.slimframework.com

Based on geggleto´s answer: 根据geggleto的答案:

if( $request->isPost() ){
  $postdata_as_array = $request->getParsedBody();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM