2

I have 4 pages in view such as

layout/header.php,
layout/header_assets.php,
user/main.php,
layout/footer.php

i want to load these multiple view so i have used this code in controller

$this->load->view('layout/header_assets');
    $this->load->view('user/main',$data);
    $this->load->view('layout/footer');

but i have got an issue :

<link rel="apple-touch-icon" href="http://localhost/game/assets/images/apple-touch-icon.png">
<html lang="en">

<head>
</head>

<body>
test
</body>
</html>
<footer>

</footer>

I want html code in proper way, header_assets load in head tag, footer load in body tag.

but right now if i load first header_assets and than load main.php. so header_assets load first after that main.php

I want it in this way

<html lang="en">

<head>
<link rel="apple-touch-icon" href="http://localhost/game/assets/images/apple-touch-icon.png">
</head>

<body>
test

<footer>

</footer>
</body>
</html>
1
  • Use $this->load->vars($data); before loading views. Docs. Commented Jan 15, 2016 at 14:30

2 Answers 2

3

You can create a folder includes under view and create a page template and add the below code in page template-

<?php $this->load->view('includes/header');
    $this->load->view($middle);
    $this->load->view('includes/footer');   
?>

And in your controller you can just call the template and pass your data like below-

$this->data['middle'] = 'public/existing_mem'; // view page to be included
 $this->load->view('includes/template',$this->data);
Sign up to request clarification or add additional context in comments.

Comments

2

For your Question

In Controller

$this->load->view('layout/header_assets',$data); # Change
$this->load->view('user/main',$data);
$this->load->view('layout/footer');

Best option is

A file should contain 3 part.

  1. Header
  2. Body
  3. Footer.

In Header

There is only contain

  1. Meta Tags
  2. All CSS and JS

    <html lang="en">    
    <head>
        <meta>....
        <link href="">....
        <script>....
    </head>
    

In Body

This should contain page displaying part and all codes. This contain

  1. <body> tag start ....
  2. All rest of your code

In Footer

This should contain

  1. Copyright
  2. Move top(id required)
  3. </body> tag close with </html>

So you can load this three View in codeigniter by

$this->load->view('layout/header');
$this->load->view('user/main',$data);
$this->load->view('layout/footer')

Comments

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.