How to build a menu from the database [SOLVED]

edited June 2012 in News & Announcements

I am trying to build a sidemenu in my header block.

The items in the menu should be taken from a table I have called: categories.

I have a categories_model.

In my header block I have this code:
$this->load->model('categories_model'); $cats = $this->categories_model->find_all(array('published' => 'yes'), 'title asc'); $sidemenu = array(); foreach($cats as $cat): $title = $cat->title; $sidemenu[$title] = $title; endforeach; $menu = $this->menu->render($sidemenu, '', NULL, 'collapsible'); echo $menu;

When I run the home page that is loading the header block, I get this error:

Message: Undefined property: MY_Loader::$categories_model

Filename: fuel/Loader.php(298) : eval()'d code

Line Number: 59

( ! ) Fatal error: Call to a member function find_all() on a non-object in C:\wamp\www\clarenssa\fuel\application\third_party\fuel\Loader.php(298) : eval()'d code on line 59

What am I doing wrong?



  • edited 3:04PM
    Ok, solved it like that:

    Created a block view called: sidemenu.

    $cats = fuel_model('categories', array('find' => 'all', 'where' => array('published' => 'yes'), 'title asc')); $sidemenu = array(); foreach($cats as $cat): $title = $cat->title; $sidemenu[$title] = $title; endforeach; $menu = $this->menu->render($sidemenu, '', NULL, 'collapsible'); echo $menu;

    In my header block added this line:

  • edited 3:04PM
    You can also use $CI->load->view
Sign In or Register to comment.