I am trying to do a POST using Luracast Restler 2.0(CRUD) and the input json contains multiple elements.
[{"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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.