CodeIgniter Forums
Structuring views ... am I going correct ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Structuring views ... am I going correct ? (/thread-9442.html)



Structuring views ... am I going correct ? - El Forum - 06-25-2008

[eluser]CARP[/eluser]
Hi guys
I'm trying to clean my first ci app's code, and well, I begun loading views in this way...

Code:
<? $this->load->view('admin/admin_header.php'); ?>    
<!-- HTML CODE FOR ACTUAL VIEW FILE -->
<? $this->load->view('admin/admin_footer.php'); ?>

but I had previously this

Code:
//inside some_controller.php ...
    $this->load->view('admin/admin_header.php');
    $this->load->view('admin/admin_login.php');
    $this->load->view('admin/admin_footer.php');

and this 3rd way

Code:
//inside some_controller.php ...
    $data['header'] = $this->load->view('admin/admin_header.php');
    $data['footer'] = $this->load->view('admin/admin_footer.php');
    $this->load->view('admin/admin_login.php',$data);

Which one of the above methods is the best way to do this? Personally, for me, the best choice is the 1st one, but I don't know if doing this isn't very advisable for CI apps...

Thanks a lot in advance...


Structuring views ... am I going correct ? - El Forum - 06-25-2008

[eluser]Dagobert Renouf[/eluser]
I say the first one too.

But did you look at the layout library ? I use it and this is the best approach in my opinion.


Structuring views ... am I going correct ? - El Forum - 06-25-2008

[eluser]CARP[/eluser]
Cool
If I understood correctly, by using that library, you'll have just 1 master view, and will use it as a holder for loading all the views, right?
I think this limits in some way the design, by having only 1 design, but well, it is a nice approach, ad you wrote

Thanks


Structuring views ... am I going correct ? - El Forum - 06-25-2008

[eluser]xwero[/eluser]
I like the template inheritance helper myself.


Structuring views ... am I going correct ? - El Forum - 06-25-2008

[eluser]parrots[/eluser]
[quote author="CARP" date="1214420627"]Cool
If I understood correctly, by using that library, you'll have just 1 master view, and will use it as a holder for loading all the views, right?
I think this limits in some way the design, by having only 1 design, but well, it is a nice approach, ad you wrote

Thanks[/quote]

I've been using the layout library Dagobert mentioned, it works great. It won't limit you to one design...you can have one "master" layout per section. When you load the library you point it to what master view file you want; all admin controllers can load it with the admin master, front-end controllers with the front-end layout, etc.


Structuring views ... am I going correct ? - El Forum - 06-25-2008

[eluser]CARP[/eluser]
[quote author="parrots" date="1214430349"]...When you load the library you point it to what master view file you want; all admin controllers can load it with the admin master, front-end controllers with the front-end layout, etc.[/quote]

great! now got the point! thanks parrots!


Structuring views ... am I going correct ? - El Forum - 06-25-2008

[eluser]CARP[/eluser]
[quote author="xwero" date="1214421159"]I like the template inheritance helper myself.[/quote]

this goes 2 far beyond my CI_NOOB status, but thanks for yout tip anyway. I'll have it into account for future (when I get more advanced with CI)