Codeigniter菜单未显示

I have issue displaying menu on the website. The link website.com/menu displaying links from the database.

enter image description here

But on the menubar of the website it is not showing. enter image description here

Controller Menu:

public function index()
{       
    $this->load->model("menu_model");
    $data = array();

    if ($menu_query = $this -> menu_model-> getCategories()) {
        $data['recordsmenu'] = $menu_query;
    }
    $this->load->view("includes/menu", $data);
}

Menu_model:

public function getCategories()
{
    $this->db->select('*');
    $this->db->from('category_name');
    $this->db->where('parent_id','0');
    $this->db->order_by('category_id', 'asc');
    $menu_query = $this->db->get();

    if ($menu_query->num_rows() != 0) {
        return $menu_query->result();
    } else {
        return false;
    }
}

Menu View:

<ul class="nav navbar-nav">
    <?php if(isset($recordsmenu)) : foreach ($recordsmenu as $menu): ?>        
    <li><a href="<?php echo base_url(); echo $menu->linkname;?>"><?php echo $menu->catname;?></a></li>
    <?php endforeach; ?>
    <?php else : ?> 
    <?php endif; ?> 
</ul>

While the Controller of all other pages of website is as:

function index()
{
    $this->load->model('slides_model');
    if ($query = $this -> slides_model-> get_records()) {
        $data['records'] = $query;
    }
    $data['main_content'] = 'home';
    $this ->load->view('includes/template', $data);
}

The template.php file in includes folder is:

<?php $this->load->view('includes/header'); ?>
<?php $this->load->view('includes/menu'); ?>
<?php $this->load->view($main_content); ?>
<?php $this->load->view('includes/footer'); ?>

I don't know the way I've done is right or not.. but its working now.

I have added this to application/core/MY_Controller.php

    function __construct()
    {
        parent::__construct();
        $this->load->model("menu_model");
        $data = array();

            if($menu_query = $this -> menu_model-> getCategories())
            {
                $data['recordsmenu'] = $menu_query;
            }

      $this-> load -> view('includes/header'); 
     $this->load->view("includes/menu", $data);

     }

& removed header & menu from template.php file

Currently your menu view is not receiving any data. An efficient solution is that you can add the following to application/core/MY_Loader.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class MY_Loader extends CI_loader{

    public function view_loader($main_content_view, $dat = array(), $return=FALSE)
    {
        if($return==TRUE):
            $content = $this->view('partials/header_view', $dat, $return);
            $content .= $this->view('partials/menu_view', $dat, $return);
            $content .= $this->view($main_content_view, $dat, $return);
            $content .= $this->view('partials/footer_view', $dat, $return);

            return $content;
        else:
            $this->view('partials/header_view', $dat);
            $this->view('partials/menu_view', $dat);
            $this->view($main_content_view, $dat);
            $this->view('partials/footer_view', $dat);
        endif;
    }

and use it in your controllers to load views in this manner:

public function method_name()
{
  if ($menu_query = $this -> menu_model-> getCategories()) {
    $data['recordsmenu'] = $menu_query;
  }
  $data['some_other_data'] = $this->model_name->method_name();
  $this->load->view_loader("main_content_view_name", $data);
}