douketangyouzh5219 2013-10-08 09:30
浏览 39
已采纳

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

I am trying to find out away to get.

Just trying to find the right way of getting it done correctly I am looking through there help index but bit confused.

I have three controllers in my controllers/common file called home.php, header.php, footer.php

I have set home.php controller to be my default one.

I tried adding the header and footer controller link to home controller like this

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

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

And on the views part

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

But the links in the controller file don't work for header and footer. Where abouts would I find the correct way so I can echo the header and footer to the views pages.

  • 写回答

1条回答 默认 最新

  • dousi8559 2013-10-08 09:48
    关注

    You need save header to variable, with third parameter set to TRUE. Then send data to 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);
    

    And view 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; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)