Hello people.
Im having troubles returning an array.
I have a controller with this statement
$data['json'] = $this->resource_model->getList($business, $superUser);The getList method is this one
if ($superUser == 0) {
$query = $this->db->get_where("resources", array('business_id' => $business));
}
else {
$query = $this->db->get("resources");
}
$data = array();
foreach ($query->result() as $row) {
$resource = new Resource_model($row->id);
array_push($data, $resource);
}
if (sizeof($data) == 0) {
return not_found_array();
}
else {
return ok_data_array($data);
}And this is ok_data_array() code:
$ret = array(
"status" => 200,
"message" => "OK",
"data" => $data
);
return $ret;Again in the controller, after load data[‘json’], i send the response to a view:
$this->load->view('common/json_response_view', $data);So debugging i saw that $data variable in getList function has the right content and also in ok_data_array but, in the controller, it has empty value.
What am i doing wrong?
the restultant json is this one:
{ “status”: 200, “message”: “OK”, “data”: [ {}, {} ] }
EDIT: i “solved” it adding the rows to the array beside adding the object. Anyway, i would like to know whats going on there.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.