[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?