将页眉和页脚codeigniter添加到控制器

时间:2013-10-08 09:30:14

标签: php html css 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 个答案:

答案 0 :(得分:1)

您需要将标头保存到变量,第三个参数设置为TRUE。 然后将数据发送到common / 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);

查看common / 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; ?>