Xtremer360 Posted January 7, 2014 Share Posted January 7, 2014 Trying to figure out why I’m getting the following error in my code. Fatal error: Cannot use object of type stdClass as array in /home/xtremer/sites/dev.justmyfiles.me/public_html/application/models/dashboard_model.php on line 21 public function get_menu() { $this->db->select('*'); $this->db->from('dashboard_menu_categories'); $query = $this->db->get(); $dashboard_menu_categories = $query->result(); foreach($dashboard_menu_categories as $category) { $links = $this->db->get_where('dashboard_menu_categories_items', array('category_id' => $category->category_id)); if ($links->num_rows > 0) { $category['links'] = $links->result(); } } return $dashboard_menu_categories; } Quote Link to comment Share on other sites More sharing options...
jcbones Posted January 7, 2014 Share Posted January 7, 2014 $category is an object. You cannot then change it to an array.Object: $category->category_id Cannot change to array: $category['links'] = $links->result(); //can't do it, oh NOES you can't. Quote Link to comment Share on other sites More sharing options...
GetFreaky Posted January 7, 2014 Share Posted January 7, 2014 (edited) Trying to figure out why I’m getting the following error in my code. Fatal error: Cannot use object of type stdClass as array in /home/xtremer/sites/dev.justmyfiles.me/public_html/application/models/dashboard_model.php on line 21 public function get_menu() { $this->db->select('*'); $this->db->from('dashboard_menu_categories'); $query = $this->db->get(); $dashboard_menu_categories = $query->result(); foreach($dashboard_menu_categories as $category) { $links = $this->db->get_where('dashboard_menu_categories_items', array('category_id' => $category->category_id)); if ($links->num_rows > 0) { $category['links'] = $links->result(); } } return $dashboard_menu_categories; } You are overriding your $category variable and trying to use it as an array. Print the contents of Category and you will see what I mean. I'm not sure where you get the "links" index key and re-assigning a new value to the same index, and what you are trying to achieve with that. Edited January 7, 2014 by GetFreaky Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.