Unlike other frameworks CodeIgniter does not have a global template system. Each Controller controls it's own output independent of the system and views are FIFO unless otherwise specified.
For instance if we have a global header:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd" >
<html>
<head>
<title><?=$title?></title>
<!-- Javascript -->
<?=$javascript ?>
<!-- Stylesheets -->
<?=$css ?>
</head>
<body>
<div id="header">
<!-- Logos, menus, etc... -->
</div>
<div id="content">
and a global footer:
</div>
<div id="footer">
<!-- Copyright, sitemap, links, etc... -->
</div>
</body>
</html>
then our controller would have to look like
<?php
class Welcome extends Controller {
function index() {
$data['title'] = 'My title';
// Javascript, CSS, etc...
$this->load->view('header', $data);
$data = array();
// Content view data
$this->load->view('my_content_view', $data);
$data = array();
// Copyright, sitemap, links, etc...
$this->load->view('footer', $data);
}
}
There are other combinations, but better solutions exist through user libraries like:
See Comments Below
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…