Php – adding header and footer codeigniter to controller

codeignitercsshtmlPHP

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.

Best Answer

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