Navigation with links from db. How?

I want to make navigation with link from a table, say 'links'.
A bad solution:
Any controller:
$this->load->view('partials/header', $data);

In ...partial/header:
<div id="container">
<div id="left_nav">
  &lt;?=foreach($for_left_nav as $link: ?&gt;
</div> //left_nav
<div id="content">

This way I make database access for each page which use left_nav, although changes in 'links' table seldom happens.
Another solution is to search in sources as wordpress or joomla, but... I'm lazy ;-)
Are anybody a better solution for that?
(As you can see, I'm not an English speaker/writer, sorry)

I've searched again and it seems that isn't another solution.
I'm a disappointed n00b!

You can use a file cache or any other cache (memory) to store the links. This way you don't have to query the db on every request. I also recommend putting this code in a Wiredesignz hmvc module.

Thanks, nmweb!
I haven't used caching yet, is a good tip.
Thanks again.

You can use something like this:

In your controller:


//instead of this->load->view
$this->layout->display('your_main_content_view', $data);


class Layout

    var $CI;

    function Layout()
        $this->CI =& get_instance();

    function display($view, $data=NULL)
        //Header with menu from DB
        $data_header['top_menu'] = 'Menu from DB...';
        $this->CI->load->view('header_view', $data_header);
        //Main content
        $this->CI->load->view($view, $data);
        $data_footer['bottom_menu'] = 'Menu bottom';
        $this->CI->load->view('footer_view', $data_footer);

[eluser]Chris Newton[/eluser]
That assumes you're already using the layout library, which isn't part of the default install:

You could also write out the navigation to a view file when the links table is updated. Long-term caching. Basically you pull the navigation from a file, rather than the database. If you're making changes to the 'links' table through an admin interface, that admin application could also write out a new view_navigation.php file at the same time the database is being updated.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.