2013-03-06 133 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