[eluser]bigtony[/eluser]
I've found this simple approach works for me:
Controller: somepage.php
Code:
<?php
class Somepage extends Controller {
function Somepage() {
parent::Controller();
}
function index() {
$view_data['title'] = 'Title of page';
$view_data['h1'] = 'H1 page header text';
$view_data['somedata'] = 'Some data for the page;
$view_data['view_template'] = 'somepage_view';
$this->load->view('layout_view', $view_data);
}
}
?>
View: layout_view.php
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<?php if (isset($h1)): ?>
<h1><?php echo $h1; ?></h1>
<?php endif; ?>
// following line loads the content specific to this page.
<?php echo $this->load->view("{$view_template}"); ?>
// other stuff can go here that appears on all pages, eg. page links.
</body>
</html>
View: somepage_view.php
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<p><?php echo $somedata; ?></p>
As you can see, each controller sets a value in the 'view_data' array with the name of the view specific to that page. Controller then calls 'layout_view' to take care of the headers, footer, etc. common to each page, and this view in turn calls the specific page view as per the 'view_data' variable value. All data in view_data is cascaded to each view automatically.
Obviously above example is bare-bones just to show the principle. It's not a perfect mvc solution as you end up putting display text in the controller (eg. title), but it's simple and it works.