Welcome Guest, Not a member yet? Register   Sign In
Multiple pages
#1

[eluser]BlueGemini[/eluser]
Hi, I need help regarding on how to display multiple pages in one page.

Normally in HTML, we use <IFRAME> and specify the path of the certain page you want to display. But how about in CI? Seems the <iframe> is not working within CI (even using base_url() to specify that view page is not working). So, how can I make certain pages display within one page?


Thanks in advance!
#2

[eluser]theprodigy[/eluser]
you can just use

Code:
$this->load->view('header');
$this->load->view('content');
$this->load->view('footer');

Is this what you were talking about?
#3

[eluser]BlueGemini[/eluser]
[quote author="theprodigy" date="1263899185"]you can just use

Code:
$this->load->view('header');
$this->load->view('content');
$this->load->view('footer');

Is this what you were talking about?[/quote]

Not quite... I already did that and it just stack the view results. I wanted to put every pages in the right layout (putting them within <div>)
#4

[eluser]theprodigy[/eluser]
Try storing your views into variables that you pass to your views
Code:
$data['div1'] = $this->load->view('mydiv1', '', true);
$data['div2'] = $this->load->view('mydiv2', '', true);
$this->load->view('layout',$data);

then just output your variables in the layout.php view

Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My Layout&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<div id="div1">
&lt;?php echo $div1; ?&gt;
</div>
<div id="div2">
&lt;?php echo $div2; ?&gt;
</div>
&lt;/body&gt;
&lt;/html&gt;

Is that more of what you are looking for?
#5

[eluser]BlueGemini[/eluser]
[quote author="theprodigy" date="1263899986"]Try storing your views into variables that you pass to your views
Code:
$data['div1'] = $this->load->view('mydiv1', '', true);
$data['div2'] = $this->load->view('mydiv2', '', true);
$this->load->view('layout',$data);

then just output your variables in the layout.php view

Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My Layout&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
<div id="div1">
&lt;?php echo $div1; ?&gt;
</div>
<div id="div2">
&lt;?php echo $div2; ?&gt;
</div>
&lt;/body&gt;
&lt;/html&gt;

Is that more of what you are looking for?[/quote]

Hey, it work. :cheese: didn't thought about that... :-P

One more question. What is the difference of having a TRUE?

Code:
$data['div1'] = $this->load->view('mydiv1', '', true);

Thank you very much! ;-)
#6

[eluser]theprodigy[/eluser]
The TRUE tells it to RETURN the output rather than ECHO the output. That way you can store it in a variable for use later. (EllisLabs thought of everything Wink )

HINT: if you need to pass variables to the views that you are storing, the second parameter is for that. If you don't, then leave as is.

With data being sent:
Code:
$data['div2'] = $this->load->view('mydiv2', $data_array, true);
WITHOUT data being sent:
Code:
$data['div2'] = $this->load->view('mydiv2', '', true);
#7

[eluser]BlueGemini[/eluser]
[quote author="theprodigy" date="1263904058"]The TRUE tells it to RETURN the output rather than ECHO the output. That way you can store it in a variable for use later. (EllisLabs thought of everything Wink )

HINT: if you need to pass variables to the views that you are storing, the second parameter is for that. If you don't, then leave as is.

With data being sent:
Code:
$data['div2'] = $this->load->view('mydiv2', $data_array, true);
WITHOUT data being sent:
Code:
$data['div2'] = $this->load->view('mydiv2', '', true);
[/quote]

Now I know :lol:

Thank you very much!
#8

[eluser]jwindhorst[/eluser]
You could also just call views from within a primary view:

Code:
<div>
     &lt;?php $this->load->view('this-divs-view');
</div>

To me this is a more readable (less abstract) solution to the problem, but of course, both work.




Theme © iAndrew 2016 - Forum software by © MyBB