Welcome Guest, Not a member yet? Register   Sign In
Navigation menu from database
#1

[eluser]Walle[/eluser]
Hello,

I am new to CodeIgniter, and I have a question which I'm not able to resolve.
I have several views, which load a navigation menu. For example this view:

Code:
<?php $this->load->view('template/header'); ?>
<?php $this->load->view('template/navigation'); ?>
<div id="page-wrapper">
    <div class="row">
        <h1>Title</h1>
    </div>
    <div class="row">
        <p>Paragraph</p>
    </div>
</div>
&lt;?php $this->load->view('template/footer'); ?&gt;

Now my question is, I have some items in the navigation file, which have to be resolved from the database. I have created a model, which returns my data as I want it. I am able to print the data on a view, so that is all right.

Code:
&lt;?php

class Menu extends CI_Model {

    public function getMenuItems() {
        $query = $this->db->query("SELECT ID, OMSCHR FROM ticket.online_help_menu_top");
        $menu = array();
        foreach ($query->result_array() as $row) {
            $menu[] = array(
                'id' => $row['ID'],
                'omschr' => $row['OMSCHR']
            );
        }
        return $menu;
    }
}

I also made a controller to load the view:

Code:
&lt;?php

class Test123 extends CI_Controller {

    public function test() {
        $this->load->model('menu');
        $data = array();
        $data['menu'] = $this->menu->getMenuItems();
        $this->load->view('template/navigation', $data);
    }
}

But if I load the view 'template/navigation', I logically just get a page with my menu on it, and not with all the other stuff like the example on the top of my post.

So my question is, how can I get the data from the Menu model into my template/navigation page, on another view, by just using
Code:
&lt;?php $this->load->view('template/navigation'); ?&gt;
inside that view?

I've been doing some research on the internet, but I wasn't able to find somehting useful on it.

If I need to post some code of the template/navigation.php file, ask it. But it is clearly simple, just a file with <ul> and <li> items, I just need to get the data in there.

I hope someone can answer my question. It would really help me out a lot.

Thanks in advance,

Jeroen


Messages In This Thread
Navigation menu from database - by El Forum - 09-02-2014, 07:32 AM
Navigation menu from database - by El Forum - 09-02-2014, 10:46 AM
Navigation menu from database - by El Forum - 09-02-2014, 11:22 AM
Navigation menu from database - by El Forum - 09-02-2014, 11:23 AM
Navigation menu from database - by El Forum - 09-03-2014, 08:02 AM
Navigation menu from database - by El Forum - 09-08-2014, 01:36 AM
Navigation menu from database - by El Forum - 09-12-2014, 02:24 PM



Theme © iAndrew 2016 - Forum software by © MyBB