3

I have a Route that activates a Controller which returns to me a page through a View. Let's call it master page.

route -> controller -> view [master page]

The master page is divided into header, sidebar, body and footer. And as the sidebar can be loaded to other pages, and not only the master page, it has its own View file.

However, the sidebar should receive the data from user, which would be obtained through a Model. And in theory, the Model could only be called by a Controller, who call the View, however, this View is the master page, not the sidebar.

[...] -> view [master page] -> view [sidebar]

So I thought the possibilities were as follows, and the idea is to know whether it is right or wrong, or perhaps it is another way that I could not imagine.

  1. The Controller will load the data from the Model and apply the sidebar which, in turn, be applied to the master page. The problem here is, in a "deeper" case, it would be extremely laborious and difficult to understand.
  2. The Controller run the Model, but send to the master page, which would be responsible for loading the View sidebar and pass the information of the Model to it. In this case, the work would be passing on information between the layers, so far as was necessary to take the information.
  3. The Controller will only load the View master page, which will load the sidebar, which will be responsible for executing the Model (inside View). The problem here is that a View theoretically should not run a Model, just print your information already processed in the Controller.

What would be the most appropriate way to make this process run correctly?

  • 1
    You could have a look at Hierarchical MVC – Bart van Ingen Schenau Jul 19 '14 at 7:24
  • The HMVC seems to solve the problem much like my second idea. However, besides the controller do all the work alone, it would transfer the building to another Controller responsible for Sidebar. And the information obtained would be passed on the Masterpage. -- But the problem of depth continue to exist when the sidebar, for example, also have a shared dependency (such as the user's avatar). -- I would be corrupting the HMVC concept if call the Controller within the View? Example: Controller -> MasterPage View -> Sidebar Controller -> Sidebar View -> Controller Avatar -> Avatar View. – David Rodrigues Jul 20 '14 at 2:42
  • 1
    The difference with your second option is that in HMVC, the Controller knows that the View needs a sub-View (like a sidebar in the MasterPage, or the Avatar in the Sidebar) and requests that sub-View from the responsible Controller just like a browser requested the initial View. The MasterPage View just gets the Sidebar it needs from its Controller and doesn't care where it came from. A more in-depth discussion can be found at techportal.inviqa.com/2010/02/22/… – Bart van Ingen Schenau Jul 20 '14 at 9:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.