0

controller: Test.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Test extends CI_Controller 
{
    function __construct() 
    {
        parent :: __construct();
        $this->load->helper(array('form', 'url'));
    }
    public function index()
    {
        $this->load->view('index');
    }
}

view : index.php

<html>
    <head>
        <title>Welcome</title>
    </head>
<body>
    <?php include('header.php'); ?>
</body>
</html>

I am new in codeigniter and I want to include header.php file in index.php and I am using include function in view but I think that is not the correct way to include header file inside the index.php then what is the correct way please help me.

Thank You

randy
  • 3
  • 1
  • Possible duplicate of [Best method of including views within views in CodeIgniter](https://stackoverflow.com/questions/15221371/best-method-of-including-views-within-views-in-codeigniter) – Mohammad Hamedani Jun 12 '17 at 05:25
  • Codeigniter doc's pretty good now https://www.codeigniter.com/user_guide/general/views.html#loading-multiple-views –  Jun 12 '17 at 05:36

3 Answers3

0

You can include like this

<html>
    <head>
        <title>Welcome</title>
    </head>
    <body>
        <?php  $this->load->view('header'); ?>
    </body>
</html>
ImBhavin95
  • 1,494
  • 2
  • 16
  • 29
0

Change your controller like this

 public function index()
{
    $this->load->view('header');
    $this->load->view('index');
}
Yadhu Babu
  • 1,503
  • 2
  • 13
  • 25
0

This is called partial views of Codeigniter on the rule of codeigniter you will include any page or header top or bottom of the website you will used controller

class Your_controller extend CI_controller{
 public function index(){
 $this->load->view('header');
 $this->load->view('index');
 }  
}