[eluser]Steve Grant[/eluser]
The way I do it is to have all output directed to a single view file, which includes a number of generic "component" files. In the controller, I then pass an array of files which contain the *actual* page content (i.e. stuff that is specific to the particular page you're viewing) and one of the "component" files contains a foreach loop on that file list to recursively include the files in the list.
File Structure:
Code:
views/
- index.php (single view file)
- global/
--- header.php (globally-included page header)
--- footer.php (globally-included page footer)
--- content.php (globally-included page "content")
- content/
--- controller1/
----- controller1_action1_init.php
----- controller1_action1_error.php
----- controller1_action1_done.php
--- controller2/
----- controller2_action1_init.php
----- controller2_action2_init.php
Controller (extract):
Code:
function index()
{
$this->data['file_list'][] = $view_path . '/content/controller1/controller1_action1_init.php';
// if we want to add more content, we can do... this allows us to separate
// the page into manageable blocks
$this->data['file_list'][] = $view_path . '/content/controller1/controller1_action1_done.php';
// load the view
$this->load->view('index', $this->data);
}
Single view file:
Code:
<html>
<?php include_once('global/header.php'); ?>
<?php include_once('global/content.php'); ?>
<?php include_once('global/footer.php'); ?>
</html>
Content file:
Code:
<?php
foreach($file_list as $file)
{
include_once($file);
}
?>