Welcome Guest, Not a member yet? Register   Sign In
modular site design - what to do with controller(s)?
#1

[eluser]deck42[/eluser]
Hello everyone,

I am planing to build a site with modules (e.g. display user info, show time, show some other data) that are gonna be present on most pages. I decided to use the following approach:

View:
Make one "wrapper" view that loads all the views of the different modules depending on some flags, e.g.: bool load_moduleX, load_moduleY, ... shall be passed to the wrapper and if load_moduleX is true it loads moduleX and so on.

Model:
Now on the model side there is no problem, I will have models for each module (as far as needed) to retreive info from the db.

BUT here comes the question: what to do with the controller level?
More precisely: each module needs retreival of data (loading and using of model) and preperation of data and functionality. Since most modules shall be loaded on every page of the site, if I use individual controllers for every page, I would have to include the code that prepares a given module in every controller. A very non-object oriented approach, big no-go for me.

Here is my solution: I move the code for preparation of moduleX, moduleY,... into a library into functions "setup_moduleX", "setup_moduleY", ... and now in the controllers I just call those library functions.
This means, that I am going to have controllers ONLY for modules that are rather unique to a page (messaging, registration,...) and they are going to call the "setup_" functions for all the modules that are also meant to show up and set the boolean "load_" variables to tell the wrapper view to load the modules.

What do you think?
How would you do it, is there a cleaner approach?
#2

[eluser]WanWizard[/eluser]
Use a modular extension, such as Modular CI or Modular Extensions HMVC.

Modular CI has been designed specifically to do what you intend to do, creating self-contained 'applications' that produce widget output instead of entire pages.
#3

[eluser]deck42[/eluser]
Wow, your solution to this (Modular CI) looks very impressive! I will try using it, thanks alot already!

I totally missed that ppl were building modular CI approaches in such clever ways...
#4

[eluser]deck42[/eluser]
One more question:

With modular CI, would you consider it a better approach to move ALL your controllers into seperate modules and keep only one "router"/"wrapper" controller (that loads the modules depending on what page is called) in the standard CI application (in this case all your links on the page would link to this router/wrapper controller)

OR

Would you keep controllers that are unique to one page of your site as standard CI controllers which act as "main" controllers of a page then and let each of them call the common module controllers that are needed? (in this case your links would point at different "main" controllers that would each call modules)


To me the first approach seems better, since it is more object oriented: you have ONE place (the "wrapper" controller) where the modules for the different pages of your site are chosen, not several "main" controllers that each load the mostly same list of modules.




Theme © iAndrew 2016 - Forum software by © MyBB