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; } Link to comment https://forums.phpfreaks.com/topic/285156-dynamically-created-navigation/ 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. Link to comment https://forums.phpfreaks.com/topic/285156-dynamically-created-navigation/#findComment-1464192 Share on other sites More sharing options...
GetFreaky 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; } 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. Link to comment https://forums.phpfreaks.com/topic/285156-dynamically-created-navigation/#findComment-1464203 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.