2013-03-06 134 views
0

我在我的ci博客网站上有一个右键菜单,其中包含类别和号码。Codeigniter - 动态右键菜单

Categories: 
    Science(24) 
    education(32) 
    .... 
    .... 

数字是方括号是该类别中的帖子总数。

我的模板文件是在这里:

$this->load->view('includes/header'); 

$this->load->view($main_content); 

$this->load->view('includes/footer'); 

我的右键菜单是在页脚文件。 我怎么能做到这一点?

回答

0

你最好有一个主视图分成divs(header,main_content,footer,right_menu)总是加载并在适当的div中加载每个视图。

<html> 
    <body> 
     <div id="header"> 
      <?php $this->load->view('header'); ?> 
     </div> 
     <div id="body"> 
      <div id="top_menu"> 
       <?php $this->load->view('top_menu'); ?> 
      </div> 
      <div id="main_content"> 
       <?php $this->load->view('main_content'); ?> 
      </div> 
     </div> 
     <div id="footer"> 
      <?php $this->load->view('footer'); ?> 
     </div> 
    </body> 
</html> 
0

您也可以使用这个系统,包括页眉/页脚等:

<?php 

/** 
* /application/core/MY_Loader.php 
* 
*/ 
class MY_Loader extends CI_Loader { 
    public function template($template_name, $vars = array(), $return = FALSE) 
    { 
     $content = $this->view('templates/header', $vars, $return); 
     $content .= $this->view($template_name, $vars, $return); 
     $content .= $this->view('templates/footer', $vars, $return); 

     if ($return) 
     { 
      return $content; 
     } 
    } 
} 

然后,在你的控制器,这是所有你需要做的:

<?php 
$this->load->template('body'); 

代码if来自用户:landons