We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Problems returning object

Development and Programming

o_Pi_DC's avatar
o_Pi_DC
1 posts
11 years ago
o_Pi_DC's avatar o_Pi_DC

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.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.