0

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 Answer 1

1

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; ?>
Sign up to request clarification or add additional context in comments.

3 Comments

Did not work got errors A PHP Error was encountered Severity: Notice Message: Undefined variable: variables Filename: common/home.php Line Number: 23
So set $variables to NULL, $variables is only array, that contains data sended to view
Using HMVC now easier. Also making a database wizard install for codeigniter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.