For any queries you can reach us at infovistarindia@gmail.com / WhatsApp us: +919158876092

Include header and footer in CodeIgniter

How to include header footer in CodeIgniter

First of all, create a common file in the view folder. In this example, I have created a file name as template.php in applications/views/innerpages directory.

File structure:

applications/view/innerpages
	- footer.php
	- header.php
	- template.php

applications/controllers
	- Welcome.php

template.php

<?php 

	$this->load->view('innerpages/header.php');
	$this->load->view($main_content);
	$this->load->view('innerpages/footer.php');

?>

In the above example, $main_content is a dynamic view for each page.

header.php

<!DOCTYPE html>
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>

footer.php

<h1><?php $heading; ?></h1>

</body>
</html>

applications/controllers/Welcome.php

class Welcome extends CI_Controller {

	public function index() {
		$data = [];
		$data[‘title’] 		= ‘Page Title’;
		$data[‘heading’]		= ‘Welcome to infovistar.com’
		$data[‘main_content’]	= ‘about_us’;	// page name
		$this->load->view(‘innerpages/template’, $data);
	}

}