0

我试图找出来。

只是试图找到正确完成它的正确方法,我正在查看帮助索引,但有点困惑。

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

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

4

1 回答 1

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; ?>
于 2013-10-08T09:48:14.320 回答