Welcome Guest, Not a member yet? Register   Sign In
multiple views
#5

[eluser]John_Betong[/eluser]
 
I prefer to use the Loader Class in the Controllers. The CodeIgniter Help file has details.
 
 
controller/home.php
Code:
...
  function index{$data=array()) {

    // ESSENTIAL to setup variables here which are passed to the sub-sections.
    $data['title'] = 'Johns-Jokes.com';

    // My convention: All parts of a web-page are prefixed with '_'
    $data['doctype'] = $this->load->view('_doctype',   $data, TRUE); // TRUE ensures item is loaded into memory
    $data['header']  = $this->load->view('_header',    $data, TRUE);
    $data['content'] = $this->load->view('_homepage',  $data, TRUE);
    $data['footer']  = $this->load->view('_footer',    $data, TRUE);

    $output = $this->load->view('home', $data, TRUE);
    echo $output;

}//endfunc index
  ...
  ...
 
 
view/home.php
Code:
<?= $doctype ?>
<head>
<?= $header ?>
  <style type="text/css">
    div {border:dotted solid 0px #f00} /* for debugging */
  </style>
</head>

<body>
  <div id='container'>&lt;?php /* width=856, */ ?&gt;
    &lt;?= $title ?&gt;
    
    <div  id='box_center'>
      &lt;?= $content ?&gt;
    </div>  
    
    <div id='footer'>
      &lt;?=$footer?&gt;
    </div>  
    
  </div>&lt;?php /* container */ ?&gt;
&lt;/body&gt;
&lt;/html&gt;
&nbsp;
This technique maybe long winded but I find it easy to go read the code, debug and to modify the view files to ensure they have no Html validation errors.
&nbsp;
&nbsp;


Messages In This Thread
multiple views - by El Forum - 09-10-2008, 11:49 PM
multiple views - by El Forum - 09-10-2008, 11:57 PM
multiple views - by El Forum - 09-11-2008, 12:16 AM
multiple views - by El Forum - 10-15-2008, 11:55 AM
multiple views - by El Forum - 10-15-2008, 07:41 PM
multiple views - by El Forum - 10-16-2008, 03:07 PM
multiple views - by El Forum - 10-16-2008, 09:37 PM



Theme © iAndrew 2016 - Forum software by © MyBB