Welcome Guest, Not a member yet? Register   Sign In
How to organize views?
#3

[eluser]mddd[/eluser]
I like to make views for all the main kinds of pages in my application. So there is a 'home' view, a 'text page' view (for displaying things like 'about us', 'terms&conditions;' etc), a 'list' view for displaying lists / search results. Each of these main views calls the blocks they need. For instance, a 'text page' view could look like:
Code:
<?php
// this is simplified code
$this->load->view('parts/header');
$this->load->view('parts/menu');
?>

<h1>&lt;?=$title?&gt;</h1>
&lt;?=$content?&gt;

&lt;?php
$this->load->view('parts/sidebar');
$this->load->view('parts/footer');
?&gt;

I have a 'parts' folder in my views folder that contains those blocks that can be called by the views that need them.

I like this approach more than using a 'generic template' view, because if you use a generic template, that template must handle every kind of page. And then you do get a lot of 'if/then' structures going on. They can make the template hard to read.

Note: this doesn't mean you have to have a view for each controller. In this example: any controller that outputs some kind of text page can use the 'textpage' view. And a controller 'search' could use different views for its initial search form and its results page.


Messages In This Thread
How to organize views? - by El Forum - 05-14-2010, 02:10 AM
How to organize views? - by El Forum - 05-14-2010, 04:16 AM
How to organize views? - by El Forum - 05-14-2010, 04:40 AM
How to organize views? - by El Forum - 05-14-2010, 04:53 AM
How to organize views? - by El Forum - 05-14-2010, 05:02 AM
How to organize views? - by El Forum - 05-14-2010, 06:12 AM
How to organize views? - by El Forum - 05-14-2010, 07:56 AM
How to organize views? - by El Forum - 05-14-2010, 09:44 AM
How to organize views? - by El Forum - 08-10-2010, 01:13 PM



Theme © iAndrew 2016 - Forum software by © MyBB