Include a view file |
[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: ------------- in the index.php file, we could have Code: <?php include 'header.php' ?> May I do the same thing with CI? Thx```
[eluser]Michael Wales[/eluser]
You can use this->load->view from within a view. View: frontpage.php Code: <? $this->load->view('_global/header'); ?>
[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
[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 Hi 123XD, Check out this thread.. I think it will answer your questions. Cheers, John_Betong
[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.
|
Welcome Guest, Not a member yet? Register Sign In |