Cannot use object of type stdClass as array - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Cannot use object of type stdClass as array (/showthread.php?tid=41646) |
Cannot use object of type stdClass as array - El Forum - 05-13-2011 [eluser]xerosis[/eluser] In my controller I am calling a model which takes data from a database: Code: $spec_info = $this->spec_model->GetSpecs(array("id" => $this->input->post('image_spec_id')), 'width, height'); This ends up with the error: "Cannot use object of type stdClass as array" How am I supposed to write it so it works? Below is the code for my spec_model Code: function GetSpecs($options = array(), $require = NULL) Cannot use object of type stdClass as array - El Forum - 05-13-2011 [eluser]toopay[/eluser] two option, return the array instead object, on your model Code: return $query->result_array(); Code: $spec_info = (array) $this->spec_model->GetSpecs(array("id" => $this->input->post('image_spec_id')), 'width, height'); Cannot use object of type stdClass as array - El Forum - 05-13-2011 [eluser]toopay[/eluser] For better understanding, you may want to read types in php : http://www.php.net/manual/en/language.types.php |