2013-10-08 30 views
0

我想找出去得到。添加頁眉和頁腳codeigniter到控制器

只是試圖找到正確的方法,讓它正確完成我正在尋找通過幫助指數,但有點困惑。

我有三個控制器在我的控制器/被叫home.php,常見的header.php文件,footer.php

我已經設置home.php控制器是我的默認值。

我嘗試添加頁眉和頁腳控制器連接到家庭控制器這樣

this->load->view('common/home'); 

$this->children = array(
'common/footer', 
'common/header' 
); 

而且在意見部分

<?php echo $header; ?> 
<div id="body"> 
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p> 

<p>If you would like to edit this page you'll find it located at:</p> 
<code>application/views/common/home.php</code> 

<p>The corresponding controller for this page is found at:</p> 
<code>application/controllers/common/home.php</code> 

<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p> 
</div> 
<?php echo $footer; ?> 

但在控制文件中的鏈接不爲頭工作和頁腳。哪裏可以找到正確的方法,以便我可以將頁眉和頁腳回顯到視圖頁面。

回答

1

您需要將標題保存到變量,並將第三個參數設置爲TRUE。 然後將數據發送到共同的/ home

$data['header'] = $this->load->view('common/header', $variables, TRUE); 
$data['footer'] = $this->load->view('common/footer', $variables, TRUE); 

$this->load->view('common/home', $data); 

和查看常見的/ home

<?php echo $header; ?> 
<div id="body"> 
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p> 

<p>If you would like to edit this page you'll find it located at:</p> 
<code>application/views/common/home.php</code> 

<p>The corresponding controller for this page is found at:</p> 
<code>application/controllers/common/home.php</code> 

<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p> 
</div> 
<?php echo $footer; ?> 
+0

沒有工作了錯誤 一個PHP錯誤遇到 嚴重性:注意 消息:未定義的變量:變量 文件名:common/home.php 行號:23 – user2814461

+0

所以將$ variables設置爲NULL,$ variables只是數組,tha t包含數據發送到查看 – Igerko

+0

使用HMVC現在更容易。還爲codeigniter安裝數據庫嚮導 – user2814461