Using the router to load multiple MVC and how to switch between them

I have created an application that uses a Router, or Front-Controller if you like, to dynamically load an MVC triad. The Router uses static routing, i.e. every URL is listed in an array and corresponds to a set of properties. I know some think it a disadvantage, but in my case there are other considerations that require this method to be implemented.

So far I can get away with using one MVC triad per ‘page’, but I assume this will soon become an obvious limitation.

I’d like to ask for an advice, how would you use the Router (or Front-Controller) to load several MVC triads, and how would you instantiate and switch between them?

My direction of thought is looping through an MVC array, each time instantiating a different triad, and running it. The view would add the output to some $content variable. When done looping that would be injected into a template and sent back.

But how would I have the view change it’s model on the fly, based on an instructions from the Router? Because If I instantiate a different triad every time, I would have problems passing variables in a flexible way between each triad.

Any thoughts?

Try not to think of “the” model, as if it were a single class or a single object. The model layer is a set of classes that serve a variety of purposes, such as entity objects, repository objects, validator objects, and so on.

Your app would invoke a particular controller action, as determined by the properties returned from your router. That controller action would invoke the model as necessary (that is to say, any of the classes within the model layer) and pass some set of values to a view template of the controller’s choosing.

The template could optionally also embed the output of another controller. That is, the template could invoke a separate controller that would do its own model and view template work, and our first template would include the result in its own output.

Some resources that might help:

EDIT: I realized from another post that you’re trying to do it Tom Butler’s way. So you can disregard everything above.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.