向控制器添加标头和页脚代码 [英] adding header and footer codeigniter to controller

查看:94
本文介绍了向控制器添加标头和页脚代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找出去找到。

只是为了找到正确的方法来完成它正确我在寻找帮助索引,但位困惑。

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

我的控制器/通用文件中有三个控制器,分别为home.php,header.php,footer.php

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

我已将home.php控制器设为我的预设值。

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

我试着将首页和页脚控制器链接添加到家庭控制器, b
$ b

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'
); 

而在视图部分

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

推荐答案

您需要保存标题变量,第三个参数设置为TRUE。
然后将数据发送到common / home

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

并查看common / home

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

这篇关于向控制器添加标头和页脚代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆