Welcome Guest, Not a member yet? Register   Sign In
loading view into another view?
#1

[eluser]nuttynibbles[/eluser]
hi,

i would like to load view into another view file.

e.g:

View files:
These are the 3 view files that will be called on every controller. They are the basic templates.
header.php
index.php
footer.php

index.php will look like this. So basically i include header.php and footer.php into index.php:
Code:
<?php    
include_once('header.php');
?>
<tr>
    <td>
    &lt;!--content--&gt;
    <table class="table_main">
        <tr><td class="td_roundertop"></td></tr>
        <tr><td class="td_content"><br />&lt;?=$content ?&gt;</td></tr>
        <tr><td class="td_rounderbottom"></td></tr>
    </table>
    </td>
</tr>
<tr><td style="height:10px;"></td></tr>
&lt;?php include_once('footer.php'); ?&gt;

this is how i will call them in the controller:
$this->data['content']="hello world";
$this->load->view('index',$this->data);

$this->data['content'] will contain the different forms or tables that will be displayed.

Therefore, register form, login form, edit profile form and etc etc, i would like to put them into view files too. For example, the files are:
register.php
login.php
editprofile.php

so now i would like to call this reigster.php view file and put them into $this->data['content'].

How can I do this? or anyone with a different idea to go about this?

Thks
#2

[eluser]Tom Glover[/eluser]
Have a look here: http://codeigniter.com/wiki/Displaying_Multiple_Views/

It shows you to ways of doing it, I prefer the second way because it means I have one template file and only my content files are reloaded constantly, this way can also be ajaxed where as way one can't.
#3

[eluser]marcmesa[/eluser]
Displaying multiple views

From the user guide:
Code:
&lt;?php

class Page extends Controller {

   function index()
   {
      $data['page_title'] = 'Your title';
      $this->load->view('header');
      $this->load->view('menu');
      $this->load->view('content', $data);
      $this->load->view('footer');
   }

}
?&gt;

Also, you don't need to use include_once(). You can use $this->load->view() from your controller if you prefer.
#4

[eluser]Michael Wales[/eluser]
I tend to do it with one master view file, then define a partial within my controller:

views/view.php
Code:
&lt;?php

  $this->load->view('_global/header');
  $this->load->view($partial);
  $this->load->view('_global/sidebar');
  $this->load->view('_global/footer');
?&gt;

controllers/post.php
Code:
&lt;?php
  function index() {
    $this->data->partial = 'post/index';
    $this->load->view('view', $this->data);
  }
?&gt;
#5

[eluser]Sumon[/eluser]
This one might be a good one.
Code:
&lt;? $this->load->view("nanny_inc/header");?&gt;
<div id="container">
  <div id="leftContainer">
    &lt;? $this->load->view("nanny_menu/left_main_menu");?&gt;
    &lt;? $this->load->view("nanny_menu/left_calendar");?&gt;
    &lt;? $this->load->view("nanny_menu/left_todays_hot_nanny");?&gt;
  </div>
  <div id="mainContainer">
    &lt;? $this->load->view("nanny_inc/top_banner");?&gt;
  </div>
</div>
&lt;? $this->load->view("nanny_inc/footer");?&gt;




Theme © iAndrew 2016 - Forum software by © MyBB