douhui7136 2016-06-29 12:19
浏览 40
已采纳

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'); ?>
  • 写回答

2条回答 默认 最新

  • doukundong9652 2016-06-30 02:52
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应