将页眉和页脚代码点火器添加到控制器


adding header and footer codeigniter to controller

我正试图找出答案。

只是想找到正确完成它的正确方法,我正在浏览那里的帮助索引,但有点困惑。

我的控制器/通用文件中有三个控制器,分别称为 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; ?>

但是控制器文件中的链接不适用于页眉和页脚。我在哪里可以找到正确的方法,以便我可以将页眉和页脚回显到视图页面。

您需要将标头保存到变量,第三个参数设置为 TRUE。然后将数据发送到公共/家庭

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

并查看公共/家庭

<?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; ?>