1

I am new to codeigniter and I have been called header and footer for all pages in view.

For this I created a new file in application/core/MY_Loader.php

class MY_Loader extends CI_Loader {

    public function template($template_name, $vars = array(), $return = FALSE) {
        if ($return):
            $content = $this->view('header', $vars, $return);
            $content .= $this->view($template_name, $vars, $return);
            $content .= $this->view('footer', $vars, $return);

            return $content;
        else:
            $this->view('header', $vars);
            $this->view($template_name, $vars);
            $this->view('footer', $vars);
        endif;
    }

}

Controller:

$this->load->template('welcome_message', $data);

What i have to do, to get the header and footer in all pages?

Currently my welcome_message view file only loaded not the header and footer.

Jagadeesh
  • 734
  • 6
  • 26

1 Answers1

0

Try changing your method to this:

public function template($template_name, $vars = array(), $return = FALSE) {
    if ($return):
        $content = $this->load->view('header', $vars, $return);
        $content .= $this->load->view($template_name, $vars, $return);
        $content .= $this->load->view('footer', $vars, $return);

        return $content;
    else:
        $this->load->view('header', $vars);
        $this->load->view($template_name, $vars);
        $this->load->view('footer', $vars);
    endif;
}
Daniel Waghorn
  • 2,997
  • 2
  • 20
  • 33