I am striving to respect the best I can the MVC pattern. It simplifies the life of a developer (or devs) a lot. The thing that I am wondering about is how to load multiple sections at a time.
To make it clear, I am going to take the example of a to-do list (it's pretty used this days). Let's say there are project -> milestones -> tasks.
What we need:
- get them all - all the projects with all the milestones with all the tasks in a nested json encoded array.
- get only the projects
- get only the milestones
- get only the tasks
For the last three, we can have separate controllers that provide us with the corresponding data. The problem shows up when we try to "get them all" in a nested json-encoded array.
What is probably the best way to handle that?
I thought of a few possibilities:
- Move the project, milestone and task generators in helper classes - this means we call them from the individual controllers and also call them when we need to get them all
- From the view of the projects, call the controller/view of the milestones (of each project) [which in turn calls the controller/view of the tasks (of each milestone)]. This might look like a simulation of 3 requests in 1.
The motivation comes from the fact that while I could fetch all the projects and then the milestones of each and then the tasks of each milestone, it would take a lot of requests. If we could get all the calls in one, it would take considerably less time to get the data, let alone that in one request the data is more organized.