[英]Luracast Restler 2.0 CRUD - JSON POST multiple elements at once
I am trying to do a POST using Luracast Restler 2.0(CRUD) and the input json contains multiple elements. 我正在尝试使用Luracast Restler 2.0(CRUD)进行POST,并且输入json包含多个元素。
[{"id":"1","email":"test@gmail.com"},{"id":"2","email":"test2@gmail.com"}]
It works fine with just one element set however it fails with multiple elements . 仅使用一个元素集就可以很好地工作,但是使用多个元素时就失败了。 Any one knows what is the solution.
任何人都知道解决方案是什么。 Thanks
谢谢
Modify the post function in the CRUD example as shown below 修改CRUD示例中的post函数,如下所示
function post($request_data=NULL) {
if(key_exists(0, $request_data)){
//array with nummeric index found
//post multiple
$r = array();
for ($i = 0; $i < count($request_data); $i++) {
if($request_data[$i])
$r[]=$this->dp->insert($this->_validate($request_data[$i]));
}
return $r;
}
//post single
return $this->dp->insert($this->_validate($request_data));
}
Now it will accept both single and multiple entry 现在它将接受单次输入和多次输入
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.