Welcome Guest, Not a member yet? Register   Sign In
Include a view file
#1

[eluser]123XD[/eluser]
Hi all,

I am just wondering with CI, if I could include a view file in another view file.

For example,

Normally when we write our php code, we have

Code:
-------------
index.php
<div class="content"></div>
-------------
header.php
<div class="header"></div>
-------------
footer.php
<div class="footer"></div>
-------------

in the index.php file, we could have
Code:
&lt;?php include 'header.php' ?&gt;
or footer include. so everytime while we change our footer it will auto changed in index or other files.

May I do the same thing with CI?

Thx```
#2

[eluser]Michael Wales[/eluser]
You can use this->load->view from within a view.

View: frontpage.php
Code:
&lt;? $this->load->view('_global/header'); ?&gt;
<h3>Front Page</h3>
<p>This is my website - it's pwntastic.</p>
&lt;? $this->load->view('_global/footer'); ?&gt;
#3

[eluser]123XD[/eluser]
cool, I got it works, thanks mate`

one more question, in CI one view file will have a controller associate with it, right?
if I just write header.php and footer.php in the view folder, does these has to has controllers associcate with it?

Code:
$this->load->view
function does not has to use it in controller, right?
#4

[eluser]John_Betong[/eluser]
[quote author="123XD" date="1190313894"]cool, I got it works, thanks mate`

one more question, in CI one view file will have a controller associate with it, right?
if I just write header.php and footer.php in the view folder, does these has to has controllers associcate with it?

Code:
$this->load->view
function does not has to use it in controller, right?[/quote]

Hi 123XD,

Check out this thread.. I think it will answer your questions.

Cheers,

John_Betong
&nbsp;
#5

[eluser]Michael Wales[/eluser]
A view file does not require a controller to be associated with it. In fact - let's change your frame of thought completely - it's impossible to associate a controller to a view, the two are completely unrelated. This will save you some mind-screwing in the long run.

The controller merely accepts a user's input (whether it a be a form submission, a URL request, etc.). The controller takes that input, interacts with the data (the model) if need be, then you load a view (which could also load views itself).

All of these steps are independent of one another, with the only requirement being a controller, but none of them are associated - it's all up to you.
#6

[eluser]123XD[/eluser]
Thanks for all,

it's more clear now`` Smile




Theme © iAndrew 2016 - Forum software by © MyBB