Php – Multi MVC processing vs Single MVC process

cakephpdjangomvcPHPruby-on-rails

I've worked fairly extensively with the MVC framework cakephp, however I'm finding that I would rather have my pages driven by the multiple MVC than by just one MVC. My reason is primarily to maintain an a more DRY principle.

In CakePHP MVC: you call a URL which calls a single MVC, which then calls the layout. What I want is: you call a URL, it processes a layout, which then calls multiple MVC's per component/block of html on the page.

When you compare JavaScript components, AJAX, and server side HTML rendering, it seems the most consistent method for building pages is through blocks of components or HTML views. That way, the view block could be situated either on the server or the client.

This is technically my ONLY disagreement with the MVC model. Outside of this, IMHO MVC rocks!

My question is: What other RAD frameworks follow the same principles as MVC but are driven rather by the View side of MVC?

I've looked at Django and Ruby on Rails, yet they seems to be more Controller driven.

Lift/Scala appears to be somewhat of a good fit, but i'm interested to see what others exist.

Best Answer

I think what you're thinking of is a concept called HMVC, which stands for Hierarchical Model View Controller.

What this means is that when you're rendering your view, you are able to dispatch a request to a completely different controller and return that view and echo it out. It behaves exactly like an ajax request, except it does not go through http, it goes through the framework and doesn't make an additional request.

This is not common in most frameworks, and the people who don't know about HMVC don't know what they're missing. It cleans up a lot of ugly patterns you see in regular MVC applications.

For example, you have a shopping cart on each page. Wouldn't it be nice to make a call to the shopping cart controller from within your code, and then allow it to handle the rendering and stuff? You can show different views for different states. Trying to do that in a class or a helper method is just a mess.

Anyways, what you came here for is a framework that works like this. The answer is Kohana. Here's the relevant docs.

Here's an example of it in use:
Request::factory('shopping_cart/display_items')->execute()-body;

Related Topic