Php Symfony2.8。如何从post请求中获取数据
如何从控制器中的POST请求接收数据? 我不用树枝Php Symfony2.8。如何从post请求中获取数据,php,json,symfony,post,save,Php,Json,Symfony,Post,Save,如何从控制器中的POST请求接收数据? 我不用树枝 public function newAction(Request $request) { //when I use $content = $request->getContent(); // as result I see "string" with need field and value. It's not json // array // value like /* string
public function newAction(Request $request)
{
//when I use
$content = $request->getContent();
// as result I see "string" with need field and value. It's not json
// array
// value like
/*
string '------WebKitFormBoundaryI12ukQBs3HdmPjvh
Content-Disposition: form-data; name="title"
"valuefortitle"
------WebKitFormBoundaryI12ukQBs3HdmPjvh
Content-Disposition: form-data; name="name"
"supername"
------WebKitFormBoundaryI12ukQBs3HdmPjvh--
' (length=253)
*/
}
或者如何将Post数据序列化(转换)为对象或数组
我使用标题为“Content-Type:application/json”的邮递员发送请求
您能告诉我如何保存文件(图像)吗?您可以用于POST请求:
$request->request->get('data');
对于获取请求:
$request->query->get('data');
对于文件查询:
$request->files.
并询问您的问题如何保存图像?
,您必须创建上传->卓越
:
$dir = $this->get('kernel')->getRootDir() . '/../web/uploads/images/';
$name = uniqid() . '.jpeg';
foreach ($request->files as $uploadedFile) {
$uploadedFile->move($dir, $name);
}
$file = $this->get('kernel')->getRootDir() . "/../web/uploads/images/" . $name;
if (file_exists($file)) {
echo "Successfully saved";
}
从请求中转储所有数据以查找可能的问题:
$request->request->all()代码>$request->request->get('content')代码>
POST:$request->request->get(“”)代码>
获取:$request->query->GET(“”)代码>结果我看到“空”。你能回答我的问题吗?我也面临类似的问题。这是我的问题