Jump to content

Dynamically Created Navigation


Xtremer360

Recommended Posts

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

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.