簡體   English   中英

如何使用PHP在苗條框架中使用request-> getBody()獲取表單數據?

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

我正在嘗試獲取表單數據。 我不知道錯誤在哪里。

<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>

這是獲取代碼

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

在應用程序運行之前,請求對象尚未完全填充。 IE $ app-> run(); 您實際上沒有正確使用Slim。 docs.slimframework.com

根據geggleto的答案:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM