Welcome Guest, Not a member yet? Register   Sign In
How do use includes?
#6

[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);
  }
?>


Messages In This Thread
How do use includes? - by El Forum - 11-07-2008, 06:03 PM
How do use includes? - by El Forum - 11-07-2008, 06:24 PM
How do use includes? - by El Forum - 11-07-2008, 06:31 PM
How do use includes? - by El Forum - 11-07-2008, 06:53 PM
How do use includes? - by El Forum - 11-07-2008, 10:39 PM
How do use includes? - by El Forum - 11-08-2008, 05:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB