Load "header", "footer" and "content" all at same time by using simple "page()" function.
Site.php Model:
Code:
<?php defined('BASEPATH') OR exit('Access Denied');
class Site extends CI_Model {
function page($page, $data = NULL) {
$data['base'] = base_url();
$data['page'] = current_url();
$this->load->view('header', $data);
$this->load->view($page, $data);
$this->load->view('footer', $data);
} #page
} #class
#EOF: ./application/models/Site.php
Make sure you autoload this "Site.php" model in your config. You need to edit "application/config/autoload.php" file and add "site" to model autoload array.
Usage in Controller:
Code:
<?php defined('BASEPATH') OR exit('Access Denied');
class Welcome extends CI_Controller {
public function index() {
$data['title'] = 'Welcome Page';
$this->site->page('welcome', $data);
} #index
} #class
#EOF: ./application/controllers/Welcome.php
header.php view:
Code:
<!DOCTYPE html>
<html lang="en">
<head>
<title><?=$title?></title>
<meta charset="utf-8">
<meta name="robots" content="all">
<link rel="stylesheet" href="<?=$base?>/style.css">
</head>
<body>
welcome.php view:
Code:
<div id="content">
<h1> Example Welcome Page! </h1>
</div> <!--#content-->
footer.php view:
Code:
<div id="footer">
All rights reserved.
</div> <!--#footer-->
</body>
</html>