multiple views

Hi everyone,
When I load multiple views,like this.
It always show the last view "foot", not "head" and "foot".
Do I forgot somethings?
How could use multiple views in my system?


[eluser]Michael Wales[/eluser]
I assume you are placing that code within your controller. Load a single view from your controller and then load your others views from that main view. I usually do something like this:

function index() {
  $this->data->partial = 'home/index';
  $this->load->view('layout', $this->data);


Multiple views inside controllers works just fine. Make sure there are no php errors in footer view, as if there are errors in any view only the view with errors will be shown. Check the source output for any hidden errors.

[eluser]Jesse Schutt[/eluser]

Are you saying that it is ok to load additional views from within a view? I'm just trying to get my head around "embedding" (Can you hear the EE-speak?) things like my footer, header, and nav views so one change will ripple through the site...



I prefer to use the Loader Class in the Controllers. The CodeIgniter Help file has details.
  function index{$data=array()) {

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

    // 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
<?= $doctype ?>
<?= $header ?>
  <style type="text/css">
    div {border:dotted solid 0px #f00} /* for debugging */

  <div id='container'>&lt;?php /* width=856, */ ?&gt;
    &lt;?= $title ?&gt;
    <div  id='box_center'>
      &lt;?= $content ?&gt;
    <div id='footer'>
  </div>&lt;?php /* container */ ?&gt;
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.

[eluser]Jesse Schutt[/eluser]

Thanks for writing this out. This makes a lot of sense!

I probably should know this, but why do you have some of the comments wrapped in php tags? Is it so they don't render to the browser?

Again, thanks for helping with this!


I am pleased that the code was useful and easy to understand.
Yes the comments wrapped in the PHP tags can only be seen in development. Just a little less code to be displayed in the browser to help bandwidth.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.