Welcome Guest, Not a member yet? Register   Sign In
Number of views
#1

[eluser]magiclko[/eluser]
Hi everybody,

I am developing a web application which has a very simple layout and its like this :

1. Header of site
2. Some toolbar and description of that toolbar and some other raw text.
3. Than i have some html text for each of the button in that toolbar.
4. Another toolbar
5. Some more html text for buttons on above toolbar.
6. Last toolbar
7. html text for buttons of above toolbar.

Each html page of this application will have a layout like above where point 4 and point 6 can be absent in some case and present in others.

Now, issue is i have loads and loads of functionalities to implement. All those functions can use either same view or different one. So, i have 3 options here :

1. use same view for each of these functionalities.. It can become quite mess and complex and i will have to write html in controller function and send it to this single view.
2. I can use separate view for each functionality. Hence, i'll have large number of views for each function.
3. I can use 3 views :1 view for 1st toolbar , 2nd view for upto level 2 toolbar and 3rd view for upto level 3 toolbar.

Can you guys suggest me what should i do? Also, the more data we pass from controller functions to corresponding view, more slow the site becomes? is that true?

Best Wishes
#2

[eluser]WanWizard[/eluser]
More views isn't a bad idea. Keep things simple, you'll thank yourself when it is time to do some maintenance on your code (or if someone else has to do that, they'll be eternally grateful).

I usually take this even a step further, and use a modular technique to also keep the code separate, so you'll have a self-contained widget. You call a module controller method, and it returns a parsed view that you insert in some div in your page template. There are two modular systems that can be used, and there are some decent template libraries around that you can use.
#3

[eluser]magiclko[/eluser]
Hi wanwizard,

Can you explain a bit more? or give me a link or something. Modular approach looks tempting Smile
#4

[eluser]WanWizard[/eluser]
There are two modular solutions (called HMVC) that are being actively maintained at the moment: Modular Extensions HMVC and Modular CI. You'll find both in the wiki.

Functionally both are more or less the same, but approach the challenge from a different angle. MX uses static classes to interact with modules, Modular CI uses the standard CI approach of working via $this (like $this->module->controller->method($vars); )

I work with a single front controller. No matter what the URI is, this controllers index method is called. This method uses the URI segments to retrieve the page layout from the database (which theme and template, which sections in the template, which widgets to load for each section, and which parameters to pass to the widget controller). It then processes them, by calling all widget controllers, store the result into an array, and then passing this array to the template (which is just a view in CI terms). And I have a complete page generated.

This allows you to build a library of widgets, and once you have that, you can very quickly build a new site. Usually, a lot of functionality is the same for every application, you only have to make the widgets that are application specific. Even the main functionality of a page (what's usually in de body of the page) is a widget in my case, from selecting from a list, editing a user, etc. Just view them as generic building blocks.
#5

[eluser]Eric Barnes[/eluser]
I personally like to use one layout view and then partial views. So for example the home page would have layout, header, footer, nav, sidebar, and then the body partial. In the end you should use what suits you but the more reusable you make the partials the better it will be.

Also for #1 you really never want to generate html in your controllers or models. All html should be in the views.
#6

[eluser]Eric Barnes[/eluser]
Man you guys are quick today Smile
#7

[eluser]Chillahan[/eluser]
Just wanted to add my two cents - I find it more useful to think of having a master template into which you are "injecting" various levels of sub-templates (like Eric mentioned).

So generally you'll only have to use one master template, which will handle the outer HTML doc definition, opening closing tags, and per-page Javascript loading as needed:

template_view.php

Then for each controller, just output the inner part to a variable and pass it to the template view generation. And the inner parts can use additional inner templates as needed - for example, you might have:

header_view.php

But inside that, you might have:

logged_in_header_view.php
logged_out_header_view.php

Additionally, in your main content, you might on some pages have:

full_width_view.php

And on others:

one_third_split_view.php

It's because of this cascading effect that I think the "injection" method is more maintainable, easier to visualize, and ultimately more useful. Splitting a page at the top level into header, sub-header, body, footer all the time can be limiting, not to mention more confusing for a separate designer to use (and to re-integrate design changes).




Theme © iAndrew 2016 - Forum software by © MyBB