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
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.

Edited by GetFreaky
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.